JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>PATTERN;
} else if (rawType == Locale.class) {
kind = Std.STD_LOCALE;
} else if (rawType == Charset.class) {
kind = Std.STD_CHARSET;
} else if (rawType == TimeZone.class) {
kind = Std.STD_TIME_ZONE;
} else if (rawType == InetAddress.class) {
kind = Std.STD_INET_ADDRESS;
} else if (rawType == InetSocketAddress.class) {
kind = Std.STD_INET_SOCKET_ADDRESS;
} else {
return null;
}
return new Std(rawType, kind);
}
/*
/**********************************************************
/* Deserializer implementations
/**********************************************************
*/
@SuppressWarnings("unchecked")
@Override
public T deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// Issue#381
if (p.getCurrentToken() == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final T value = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single '" + _valueClass.getName() + "' value but there was more than a single value in the array");
}
return value;
}
// 22-Sep-2012, tatu: For 2.1, use this new method, may force coercion:
String text = p.getValueAsString();
if (text != null) { // has String representation
if (text.length() == 0 || (text = text.trim()).length() == 0) {
// 04-Feb-2013, tatu: Usually should become null; but not always
return _deserializeFromEmptyString();
}
Exception cause = null;
try {
T result = _deserialize(text, ctxt);
if (result != null) {
return result;
}
} catch (IllegalArgumentException iae) {
cause = iae;
}
String msg = "not a valid textual representation";
if (cause != null) {
String m2 = cause.getMessage();
if (m2 != null) {
msg = msg + ", problem: "+m2;
}
}
JsonMappingException e = ctxt.weirdStringException(text, _valueClass, msg);
if (cause !=
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
case STD_INET_SOCKET_ADDRESS:
if (value.startsWith("[")) {
// bracketed IPv6 (with port number)
int i = value.lastIndexOf(']');
if (i == -1) {
throw new InvalidFormatException(ctxt.getParser(),
"Bracketed IPv6 address must contain closing bracket",
value, InetSocketAddress.class);
}
int j = value.indexOf(':', i);
int port = j > -1 ? Integer.parseInt(value.substring(j + 1)) : 0;
return new InetSocketAddress(value.substring(0, i + 1), port);
} else {
int ix = value.indexOf(':');
if (ix >= 0 && value.indexOf(':', ix + 1) < 0) {
// host:port
int port = Integer.parseInt(value.substring(ix+1));
return new InetSocketAddress(value.substring(0, ix), port);
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.net.InetAddress;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
/**
* Simple serializer for {@link java.net.InetAddress}. Main complexity is
* with registration, since same serializer is to be used for sub-classes.
*/
@SuppressWarnings("serial")
public class InetAddressSerializer
extends StdScalarSerializer<InetAddress>
{
public InetAddressSerializer() { super(InetAddress.class); }
@Override
public void serialize(InetAddress value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
// Ok: get textual description; choose "more specific" part
String str = value.toString().trim();
int ix = str.indexOf('/');
if (ix >= 0) {
if (ix == 0) { // missing host name; use address
str = str.substring(1);
} else { // otherwise use name
str = str.substring(0, ix);
}
}
jgen.writeString(str);
}
@Override
public void serializeWithType(InetAddress value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonGenerationException
{
// Better ensure we don't use specific sub-classes...
typeSer.writeTypePrefixForScalar(value, jgen, InetAddress.class);
serialize(value, jgen, provider);
typeSer.writeTypeSuffixForScalar(value, jgen);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>, paramClass);
}
/*
/**********************************************************
/* Default JsonDeserializer implementation
/**********************************************************
*/
/**
* Because of costs associated with constructing Enum resolvers,
* let's cache instances by default.
*/
@Override
public boolean isCachable() { return true; }
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken curr = p.getCurrentToken();
// Usually should just get string value:
if (curr == JsonToken.VALUE_STRING || curr == JsonToken.FIELD_NAME) {
CompactStringObjectMap lookup = ctxt.isEnabled(DeserializationFeature.READ_ENUMS_USING_TO_STRING)
? _getToStringLookup() : _lookupByName;
final String name = p.getText();
Object result = lookup.find(name);
if (result == null) {
return _deserializeAltString(p, ctxt, lookup, name);
}
return result;
}
// But let's consider int acceptable as well (if within ordinal range)
if (curr == JsonToken.VALUE_NUMBER_INT) {
// ... unless told not to do that
int index = p.getIntValue();
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS)) {
_failOnNumber(ctxt, p, index);
}
if (index >= 0 && index < _enumsByIndex.length) {
return _enumsByIndex[index];
}
if (!ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
throw ctxt.weirdNumberException(index, _enumClass(),
"index value outside legal index range [0.."+(_enumsByIndex.length-1)+"]");
}
return null;
}
return _deserializeOther(p, ctxt);
}
/*
/**********************************************************
/* Internal helper methods
/**********************************************************
*/
private final Object _deserializeAltString(JsonParser p, DeserializationContext ctxt,
CompactStringObjectMap lookup, String name) throws IOException
{
name = name.trim();
if (name.length() == 0) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
return null;
}
} else {
// [databind#149]: Allow use of 'String' indexes as well
char c = name.charAt(0);
if (c >= '0' && c <= '9') {
try {
int ix = Integer.
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>parseInt(name);
if (ctxt.isEnabled(DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS)) {
_failOnNumber(ctxt, p, ix);
}
if (ix >= 0 && ix < _enumsByIndex.length) {
return _enumsByIndex[ix];
}
} catch (NumberFormatException e) {
// fine, ignore, was not an integer
}
}
}
if (!ctxt.isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
throw ctxt.weirdStringException(name, _enumClass(),
"value not one of declared Enum instance names: "+lookup.keys());
}
return null;
}
protected Object _deserializeOther(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken curr = p.getCurrentToken();
// [databind#381]
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)
&& p.isExpectedStartArrayToken()) {
p.nextToken();
final Object parsed = deserialize(p, ctxt);
curr = p.nextToken();
if (curr != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single '" + _enumClass().getName() + "' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_enumClass());
}
protected void _failOnNumber(DeserializationContext ctxt, JsonParser p, int index)
throws IOException
{
throw InvalidFormatException.from(p,
String.format("Not allowed to deserialize Enum value out of JSON number (%d): disable DeserializationConfig.DeserializationFeature.FAIL_ON_NUMBERS_FOR_ENUMS to allow",
index),
index, _enumClass());
}
protected Class<?> _enumClass() {
return handledType();
}
protected CompactStringObjectMap _getToStringLookup()
{
CompactStringObjectMap lookup = _lookupByToString;
// note: exact locking not needed; all we care for here is to try to
// reduce contention for the initial resolution
if (lookup == null) {
synchronized (this) {
lookup = EnumResolver.constructUnsafeUsingToString(_enumClass())
.constructLookup();
}
_lookupByToString = lookup;
}
return lookup;
}
/*
/**********************************************************
/* Additional helper classes
/**********************************************************
*/
/**
* Deserializer that uses
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>.append(String.valueOf(_propertyIds.iterator().next()));
sb.append('"');
} else {
sb.append(" (").append(len).append(" known properties: ");
Iterator<Object> it = _propertyIds.iterator();
while (it.hasNext()) {
sb.append('"');
sb.append(String.valueOf(it.next()));
sb.append('"');
// one other thing: limit max length
if (sb.length() > MAX_DESC_LENGTH) {
sb.append(" [truncated]");
break;
}
if (it.hasNext()) {
sb.append(", ");
}
}
}
sb.append("])");
_propertiesAsString = suffix = sb.toString();
}
return suffix;
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Method for accessing type (class) that is missing definition to allow
* binding of the unrecognized property.
*/
public Class<?> getReferringClass() {
return _referringClass;
}
/**
* Convenience method for accessing logical property name that could
* not be mapped. Note that it is the last path reference in the
* underlying path.
*/
public String getPropertyName() {
return _propertyName;
}
public Collection<Object> getKnownPropertyIds()
{
if (_propertyIds == null) {
return null;
}
return Collections.unmodifiableCollection(_propertyIds);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
try {
return _factory.findClass(className);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw _problem(tokens, "Can not locate class '"+className+"', problem: "+e.getMessage());
}
}
protected IllegalArgumentException _problem(MyTokenizer tokens, String msg)
{
return new IllegalArgumentException("Failed to parse type '"+tokens.getAllInput()
+"' (remaining: '"+tokens.getRemainingInput()+"'): "+msg);
}
final static class MyTokenizer
extends StringTokenizer
{
protected final String _input;
protected int _index;
protected String _pushbackToken;
public MyTokenizer(String str) {
super(str, "<,>", true);
_input = str;
}
@Override
public boolean hasMoreTokens() {
return (_pushbackToken != null) || super.hasMoreTokens();
}
@Override
public String nextToken() {
String token;
if (_pushbackToken != null) {
token = _pushbackToken;
_pushbackToken = null;
} else {
token = super.nextToken();
}
_index += token.length();
return token;
}
public void pushBack(String token) {
_pushbackToken = token;
_index -= token.length();
}
public String getAllInput() { return _input; }
public String getUsedInput() { return _input.substring(0, _index); }
public String getRemainingInput() { return _input.substring(_index); }
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.lang.reflect.TypeVariable;
import com.fasterxml.jackson.databind.JavaType;
/**
* Type that represents "true" Java Map types.
*/
public final class MapType extends MapLikeType
{
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
private MapType(Class<?> mapType, TypeBindings bindings,
JavaType superClass, JavaType[] superInts, JavaType keyT, JavaType valueT,
Object valueHandler, Object typeHandler, boolean asStatic) {
super(mapType, bindings, superClass, superInts,
keyT, valueT, valueHandler, typeHandler, asStatic);
}
/**
* @since 2.7
*/
protected MapType(TypeBase base, JavaType keyT, JavaType valueT) {
super(base, keyT, valueT);
}
/**
* @since 2.7
*/
public static MapType construct(Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInts,
JavaType keyT, JavaType valueT) {
return new MapType(rawType, bindings, superClass, superInts, keyT, valueT, null, null, false);
}
@Deprecated // since 2.7
public static MapType construct(Class<?> rawType, JavaType keyT, JavaType valueT)
{
// First: may need to fabricate TypeBindings (needed for refining into
// concrete collection types, as per [databind#1102])
TypeVariable<?>[] vars = rawType.getTypeParameters();
TypeBindings bindings;
if ((vars == null) || (vars.length != 2)) {
bindings = TypeBindings.emptyBindings();
} else {
bindings = TypeBindings.create(rawType, keyT, valueT);
}
// !!! TODO: Wrong, does have supertypes
return new MapType(rawType, bindings, _bogusSuperClass(rawType), null,
keyT, valueT, null, null, false);
}
@Deprecated // since 2.7
@Override
protected JavaType _narrow(Class<?> subclass) {
return new MapType(subclass, _bindings,
_superClass, _superInterfaces, _keyType, _valueType,
_valueHandler, _typeHandler, _asStatic);
}
@Override
public MapType withTypeHandler(Object h) {
return new MapType
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>ArgType)) {
return am.getAnnotated();
}
}
}
}
return null;
}
protected boolean isFactoryMethod(AnnotatedMethod am)
{
/* First: return type must be compatible with the introspected class
* (i.e. allowed to be sub-class, although usually is the same
* class)
*/
Class<?> rt = am.getRawReturnType();
if (!getBeanClass().isAssignableFrom(rt)) {
return false;
}
/* Also: must be a recognized factory method, meaning:
* (a) marked with @JsonCreator annotation, or
* (b) "valueOf" (at this point, need not be public)
*/
if (_annotationIntrospector.hasCreatorAnnotation(am)) {
return true;
}
final String name = am.getName();
if ("valueOf".equals(name)) {
return true;
}
// [Issue#208] Also accept "fromString()", if takes String or CharSequence
if ("fromString".equals(name)) {
if (1 == am.getParameterCount()) {
Class<?> cls = am.getRawParameterType(0);
if (cls == String.class || CharSequence.class.isAssignableFrom(cls)) {
return true;
}
}
}
return false;
}
/**
* @deprecated Since 2.4, use <code>findCreatorParameterNames()</code> instead.
*/
@Deprecated
public List<String> findCreatorPropertyNames()
{
List<PropertyName> params = findCreatorParameterNames();
if (params.isEmpty()) {
return Collections.emptyList();
}
List<String> result = new ArrayList<String>(params.size());
for (PropertyName name : params) {
result.add(name.getSimpleName());
}
return result;
}
/**
* @deprecated Since 2.5, does not seem to be used at all.
*/
@Deprecated
public List<PropertyName> findCreatorParameterNames()
{
for (int i = 0; i < 2; ++i) {
List<? extends AnnotatedWithParams> l = (i == 0)
? getConstructors() : getFactoryMethods();
for (AnnotatedWithParams creator : l) {
int argCount = creator.getParameterCount();
if (argCount < 1) continue;
PropertyName name = _findCreatorPropertyName(creator.getParameter(0));
if (name == null || name.isEmpty()) {
continue;
}
List<PropertyName> names = new ArrayList<PropertyName>();
names.add(
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>name);
for (int p = 1; p < argCount; ++p) {
name = _findCreatorPropertyName(creator.getParameter(p));
names.add(name);
}
return names;
}
}
return Collections.emptyList();
}
protected PropertyName _findCreatorPropertyName(AnnotatedParameter param)
{
PropertyName name = _annotationIntrospector.findNameForDeserialization(param);
if (name == null || name.isEmpty()) {
String str = _annotationIntrospector.findImplicitPropertyName(param);
if (str != null && !str.isEmpty()) {
name = PropertyName.construct(str);
}
}
return name;
}
/*
/**********************************************************
/* Introspection for deserialization, other
/**********************************************************
*/
@Override
public Class<?> findPOJOBuilder() {
return (_annotationIntrospector == null) ?
null : _annotationIntrospector.findPOJOBuilder(_classInfo);
}
@Override
public JsonPOJOBuilder.Value findPOJOBuilderConfig()
{
return (_annotationIntrospector == null) ?
null : _annotationIntrospector.findPOJOBuilderConfig(_classInfo);
}
@Override
public Converter<Object,Object> findDeserializationConverter()
{
if (_annotationIntrospector == null) {
return null;
}
return _createConverter(_annotationIntrospector.findDeserializationConverter(_classInfo));
}
@Override
public String findClassDescription() {
return (_annotationIntrospector == null) ?
null : _annotationIntrospector.findClassDescription(_classInfo);
}
/*
/**********************************************************
/* Helper methods for field introspection
/**********************************************************
*/
/**
* @param ignoredProperties (optional) names of properties to ignore;
* any fields that would be recognized as one of these properties
* is ignored.
* @param forSerialization If true, will collect serializable property
* fields; if false, deserializable
*
* @return Ordered Map with logical property name as key, and
* matching field as value.
*
* @deprecated Since 2.7.2, does not seem to be used?
*/
@Deprecated
public LinkedHashMap<String,AnnotatedField> _findPropertyFields(
Collection<String> ignoredProperties, boolean forSerialization)
{
LinkedHashMap<String,AnnotatedField> results = new LinkedHashMap<String,AnnotatedField>();
for (BeanPropertyDefinition property : _properties()) {
AnnotatedField f = property.getField();
if (
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> let's use that instance, to reduce extra concurrent work.
ClassMetadata old = sCached.putIfAbsent(cls, md);
if (old != null) {
md = old;
}
}
return md;
}
/*
/**********************************************************
/* Method type detection methods
/**********************************************************
*/
/**
* @deprecated Since 2.6 not used; may be removed before 3.x
*/
@Deprecated // since 2.6
public static boolean hasGetterSignature(Method m)
{
// First: static methods can't be getters
if (Modifier.isStatic(m.getModifiers())) {
return false;
}
// Must take no args
Class<?>[] pts = m.getParameterTypes();
if (pts != null && pts.length != 0) {
return false;
}
// Can't be a void method
if (Void.TYPE == m.getReturnType()) {
return false;
}
// Otherwise looks ok:
return true;
}
/*
/**********************************************************
/* Exception handling
/**********************************************************
*/
/**
* Method that can be used to find the "root cause", innermost
* of chained (wrapped) exceptions.
*/
public static Throwable getRootCause(Throwable t)
{
while (t.getCause() != null) {
t = t.getCause();
}
return t;
}
/**
* Method that will unwrap root causes of given Throwable, and throw
* the innermost {@link Exception} or {@link Error} as is.
* This is useful in cases where mandatory wrapping is added, which
* is often done by Reflection API.
*/
public static void throwRootCause(Throwable t) throws Exception
{
t = getRootCause(t);
if (t instanceof Exception) {
throw (Exception) t;
}
throw (Error) t;
}
/**
* Method that will wrap 't' as an {@link IllegalArgumentException} if it
* is a checked exception; otherwise (runtime exception or error) throw as is
*/
public static void throwAsIAE(Throwable t)
{
throwAsIAE(t, t.getMessage());
}
/**
* Method that will wrap 't' as an {@link IllegalArgumentException} (and with
* specified message) if it
* is a checked exception; otherwise (runtime exception or error) throw as is
*/
public static void throwAsIAE(Throwable t, String msg)
{
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
if (
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>() || isObjectOrPrimitive()) {
result = NO_CTORS;
} else {
Constructor<?>[] rawCtors = _forClass.getDeclaredConstructors();
final int len = rawCtors.length;
result = new Ctor[len];
for (int i = 0; i < len; ++i) {
result[i] = new Ctor(rawCtors[i]);
}
}
_constructors = result;
}
return result;
}
// 21-Spe-2015, tatu: Surprisingly significant improvement (+10%)...
public Field[] getDeclaredFields() {
Field[] fields = _fields;
if (fields == null) {
fields = _forClass.getDeclaredFields();
_fields = fields;
}
return fields;
}
// 21-Spe-2015, tatu: Surprisingly significant improvement (+30%)...
public Method[] getDeclaredMethods() {
Method[] methods = _methods;
if (methods == null) {
methods = _forClass.getDeclaredMethods();
_methods = methods;
}
return methods;
}
// Prominently listed on profiling when not cached, improvement
// modest, 1-2% range; but at least is measurable so keep it
public boolean hasEnclosingMethod() {
Boolean b = _hasEnclosingMethod;
if (b == null) {
b = isObjectOrPrimitive() ? Boolean.FALSE : Boolean.valueOf(_forClass.getEnclosingMethod() != null);
_hasEnclosingMethod = b;
}
return b.booleanValue();
}
private boolean isObjectOrPrimitive() {
return (_forClass == CLS_OBJECT) || _forClass.isPrimitive();
}
/* And then we have a bunch of accessors that did show up in profiling
* of "wasteful" cases, but for which caching did not yield non-trivial
* improvements (for tests less than 1% improvement)
*/
// Caching does not seem worthwhile, as per profiling
// public Type getGenericSuperclass();
// public Class<?> getDeclaringClass();
// public Class<?> getEnclosingClass();
}
/**
* Value class used for caching Constructor declarations; used because
* caching done by JDK appears to be somewhat inefficient for some use cases.
*
* @since 2.7
*/
public final static class Ctor
{
public final Constructor<?> _ctor;
private Annotation[] _annotations;
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> private Annotation[][] _paramAnnotations;
private int _paramCount = -1;
public Ctor(Constructor<?> ctor) {
_ctor = ctor;
}
public Constructor<?> getConstructor() {
return _ctor;
}
public int getParamCount() {
int c = _paramCount;
if (c < 0) {
c = _ctor.getParameterTypes().length;
_paramCount = c;
}
return c;
}
public Class<?> getDeclaringClass() {
return _ctor.getDeclaringClass();
}
// Modest boost: maybe 1%?
public Annotation[] getDeclaredAnnotations() {
Annotation[] result = _annotations;
if (result == null) {
result = _ctor.getDeclaredAnnotations();
_annotations = result;
}
return result;
}
// Modest boost: maybe 1%?
public Annotation[][] getParameterAnnotations() {
Annotation[][] result = _paramAnnotations;
if (result == null) {
result = _ctor.getParameterAnnotations();
_paramAnnotations = result;
}
return result;
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.jsontype.impl;
import java.util.*;
import com.fasterxml.jackson.databind.AnnotationIntrospector;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.cfg.MapperConfig;
import com.fasterxml.jackson.databind.introspect.*;
import com.fasterxml.jackson.databind.jsontype.NamedType;
import com.fasterxml.jackson.databind.jsontype.SubtypeResolver;
/**
* Standard {@link SubtypeResolver} implementation.
*/
public class StdSubtypeResolver
extends SubtypeResolver
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
protected LinkedHashSet<NamedType> _registeredSubtypes;
public StdSubtypeResolver() { }
/*
/**********************************************************
/* Subtype registration
/**********************************************************
*/
@Override
public void registerSubtypes(NamedType... types) {
if (_registeredSubtypes == null) {
_registeredSubtypes = new LinkedHashSet<NamedType>();
}
for (NamedType type : types) {
_registeredSubtypes.add(type);
}
}
@Override
public void registerSubtypes(Class<?>... classes) {
NamedType[] types = new NamedType[classes.length];
for (int i = 0, len = classes.length; i < len; ++i) {
types[i] = new NamedType(classes[i]);
}
registerSubtypes(types);
}
/*
/**********************************************************
/* Resolution by class (serialization)
/**********************************************************
*/
@Override
public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config,
AnnotatedMember property, JavaType baseType)
{
final AnnotationIntrospector ai = config.getAnnotationIntrospector();
// for backwards compatibility, must allow null here:
Class<?> rawBase = (baseType == null) ? property.getRawType() : baseType.getRawClass();
HashMap<NamedType, NamedType> collected = new HashMap<NamedType, NamedType>();
// start with registered subtypes (which have precedence)
if (_registeredSubtypes != null) {
for (NamedType subtype : _registeredSubtypes) {
// is it a subtype of root type?
if (rawBase.isAssignableFrom(subtype.getType())) { // yes
AnnotatedClass curr = AnnotatedClass.constructWithoutSuperTypes(subtype.getType(), config);
_collectAndResolve(curr, subtype, config, ai, collected);
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>JacksonInFiveMinutes")
*/
protected static class FiveMinuteUser {
public enum Gender { MALE, FEMALE };
public static class Name
{
private String _first, _last;
public Name() { }
public Name(String f, String l) {
_first = f;
_last = l;
}
public String getFirst() { return _first; }
public String getLast() { return _last; }
public void setFirst(String s) { _first = s; }
public void setLast(String s) { _last = s; }
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
Name other = (Name) o;
return _first.equals(other._first) && _last.equals(other._last);
}
}
private Gender _gender;
private Name _name;
private boolean _isVerified;
private byte[] _userImage;
public FiveMinuteUser() { }
public FiveMinuteUser(String first, String last, boolean verified, Gender g, byte[] data)
{
_name = new Name(first, last);
_isVerified = verified;
_gender = g;
_userImage = data;
}
public Name getName() { return _name; }
public boolean isVerified() { return _isVerified; }
public Gender getGender() { return _gender; }
public byte[] getUserImage() { return _userImage; }
public void setName(Name n) { _name = n; }
public void setVerified(boolean b) { _isVerified = b; }
public void setGender(Gender g) { _gender = g; }
public void setUserImage(byte[] b) { _userImage = b; }
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
FiveMinuteUser other = (FiveMinuteUser) o;
if (_isVerified != other._isVerified) return false;
if (_gender != other._gender) return false;
if (!_name.equals(other._name)) return false;
byte[] otherImage = other._userImage;
if (otherImage.length != _userImage.length) return false;
for (int i = 0, len = _userImage.length; i < len; ++i) {
if (_
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>userImage[i] != otherImage[i]) {
return false;
}
}
return true;
}
}
/*
/**********************************************************
/* High-level helpers
/**********************************************************
*/
protected void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents)
throws IOException
{
verifyJsonSpecSampleDoc(jp, verifyContents, true);
}
protected void verifyJsonSpecSampleDoc(JsonParser jp, boolean verifyContents,
boolean requireNumbers)
throws IOException
{
if (!jp.hasCurrentToken()) {
jp.nextToken();
}
assertToken(JsonToken.START_OBJECT, jp.getCurrentToken()); // main object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Image'
if (verifyContents) {
verifyFieldName(jp, "Image");
}
assertToken(JsonToken.START_OBJECT, jp.nextToken()); // 'image' object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Width'
if (verifyContents) {
verifyFieldName(jp, "Width");
}
verifyIntToken(jp.nextToken(), requireNumbers);
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_WIDTH);
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Height'
if (verifyContents) {
verifyFieldName(jp, "Height");
}
verifyIntToken(jp.nextToken(), requireNumbers);
if (verifyContents) {
verifyIntValue(jp, SAMPLE_SPEC_VALUE_HEIGHT);
}
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Title'
if (verifyContents) {
verifyFieldName(jp, "Title");
}
assertToken(JsonToken.VALUE_STRING, jp.nextToken());
assertEquals(SAMPLE_SPEC_VALUE_TITLE, getAndVerifyText(jp));
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Thumbnail'
if (verifyContents) {
verifyFieldName(jp, "Thumbnail");
}
assertToken(JsonToken.START_OBJECT, jp.nextToken()); // 'thumbnail' object
assertToken(JsonToken.FIELD_NAME, jp.nextToken()); // 'Url'
if (verifyContents) {
verifyFieldName(jp, "Url");
}
assertToken(JsonToken.VALUE_STRING, jp.nextToken());
if (verifyContents) {
assertEquals(SAMPLE_SPEC_VALUE_TN_URL, getAndVerifyText(jp));
}
assertToken(JsonToken.
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>getName()+", got null");
}
Class<?> cls = ob.getClass();
if (!expType.isAssignableFrom(cls)) {
fail("Expected type "+expType.getName()+", got "+cls.getName());
}
}
protected void assertValidLocation(JsonLocation location) {
assertNotNull("Should have non-null location", location);
assertTrue("Should have positive line number", location.getLineNr() > 0);
}
protected void verifyException(Throwable e, String... matches)
{
String msg = e.getMessage();
String lmsg = (msg == null) ? "" : msg.toLowerCase();
for (String match : matches) {
String lmatch = match.toLowerCase();
if (lmsg.indexOf(lmatch) >= 0) {
return;
}
}
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}
/**
* Method that gets textual contents of the current token using
* available methods, and ensures results are consistent, before
* returning them
*/
protected String getAndVerifyText(JsonParser jp)
throws IOException, JsonParseException
{
// Ok, let's verify other accessors
int actLen = jp.getTextLength();
char[] ch = jp.getTextCharacters();
String str2 = new String(ch, jp.getTextOffset(), actLen);
String str = jp.getText();
if (str.length() != actLen) {
fail("Internal problem (jp.token == "+jp.getCurrentToken()+"): jp.getText().length() ['"+str+"'] == "+str.length()+"; jp.getTextLength() == "+actLen);
}
assertEquals("String access via getText(), getTextXxx() must be the same", str, str2);
return str;
}
/*
/**********************************************************
/* And other helpers
/**********************************************************
*/
protected byte[] encodeInUTF32BE(String input)
{
int len = input.length();
byte[] result = new byte[len * 4];
int ptr = 0;
for (int i = 0; i < len; ++i, ptr += 4) {
char c = input.charAt(i);
result[ptr] = result[ptr+1] = (byte) 0;
result[ptr+2] = (byte) (c >> 8);
result[ptr+3] = (byte) c;
}
return result;
}
public String quote(String str) {
return '"'+
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>str+'"';
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> == null) {
deser = findDeserializer(ctxt, prop.getType(), prop);
}
prop = prop.withValueDeserializer(deser);
} else { // may need contextual version
JsonDeserializer<Object> deser = prop.getValueDeserializer();
/* Important! This is the only place where actually handle "primary"
* property deserializers -- call is different from other places.
*/
JsonDeserializer<?> cd = ctxt.handlePrimaryContextualization(deser, prop,
prop.getType());
if (cd != deser) {
prop = prop.withValueDeserializer(cd);
}
}
// Need to link managed references with matching back references
prop = _resolveManagedReferenceProperty(ctxt, prop);
// [databind#351[: need to wrap properties that require object id resolution.
if (!(prop instanceof ManagedReferenceProperty)) {
prop = _resolvedObjectIdProperty(ctxt, prop);
}
// Support unwrapped values (via @JsonUnwrapped)
SettableBeanProperty u = _resolveUnwrappedProperty(ctxt, prop);
if (u != null) {
prop = u;
if (unwrapped == null) {
unwrapped = new UnwrappedPropertyHandler();
}
unwrapped.addProperty(prop);
/* 12-Dec-2014, tatu: As per [databind#647], we will have problems if
* the original property is left in place. So let's remove it now.
*/
_beanProperties.remove(prop);
continue;
}
// non-static inner classes too:
prop = _resolveInnerClassValuedProperty(ctxt, prop);
if (prop != origProp) {
_beanProperties.replace(prop);
// [databind#795]: Make sure PropertyBasedCreator's properties stay in sync
if (creatorProps != null) {
// 18-May-2015, tatu: _Should_ start with consistent set. But can we really
// fully count on this? May need to revisit in future; seems to hold for now.
for (int i = 0, len = creatorProps.length; i < len; ++i) {
if (creatorProps[i] == origProp) {
creatorProps[i] = prop;
break;
}
// ... as per above, it is possible we'd need to add this as fallback
// if (but only if) identity check fails?
/*
if (creatorProps[i].getName().equals(prop.getName())) {
creatorProps[i] = prop;
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
ObjectIdReader oir = _objectIdReader;
// First: may have an override for Object Id:
final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
final AnnotatedMember accessor = (property == null || intr == null)
? null : property.getMember();
if (accessor != null && intr != null) {
ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor);
if (objectIdInfo != null) { // some code duplication here as well (from BeanDeserializerFactory)
// 2.1: allow modifications by "id ref" annotations as well:
objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo);
Class<?> implClass = objectIdInfo.getGeneratorType();
// Property-based generator is trickier
JavaType idType;
SettableBeanProperty idProp;
ObjectIdGenerator<?> idGen;
ObjectIdResolver resolver = ctxt.objectIdResolverInstance(accessor, objectIdInfo);
if (implClass == ObjectIdGenerators.PropertyGenerator.class) {
PropertyName propName = objectIdInfo.getPropertyName();
idProp = findProperty(propName);
if (idProp == null) {
throw new IllegalArgumentException("Invalid Object Id definition for "
+handledType().getName()+": can not find property with name '"+propName+"'");
}
idType = idProp.getType();
idGen = new PropertyBasedObjectIdGenerator(objectIdInfo.getScope());
} else { // other types need to be simpler
JavaType type = ctxt.constructType(implClass);
idType = ctxt.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0];
idProp = null;
idGen = ctxt.objectIdGeneratorInstance(accessor, objectIdInfo);
}
JsonDeserializer<?> deser = ctxt.findRootValueDeserializer(idType);
oir = ObjectIdReader.construct(idType, objectIdInfo.getPropertyName(),
idGen, deser, idProp, resolver);
}
}
// either way, need to resolve serializer:
BeanDeserializerBase contextual = this;
if (oir != null && oir != _objectIdReader) {
contextual = contextual.withObjectIdReader(oir);
}
// And possibly add more properties to ignore
if (accessor != null) {
String[] ignorals = intr.findPropertiesToIgnore(accessor, false);
if (ignorals != null && ignorals.length != 0
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>getObjectIdReader();
if (objectIdInfo == null && objectIdReader == null) {
return prop;
}
return new ObjectIdReferenceProperty(prop, objectIdInfo);
}
/**
* Helper method called to see if given property might be so-called unwrapped
* property: these require special handling.
*/
protected SettableBeanProperty _resolveUnwrappedProperty(DeserializationContext ctxt,
SettableBeanProperty prop)
{
AnnotatedMember am = prop.getMember();
if (am != null) {
NameTransformer unwrapper = ctxt.getAnnotationIntrospector().findUnwrappingNameTransformer(am);
if (unwrapper != null) {
JsonDeserializer<Object> orig = prop.getValueDeserializer();
JsonDeserializer<Object> unwrapping = orig.unwrappingDeserializer(unwrapper);
if (unwrapping != orig && unwrapping != null) {
// might be cleaner to create new instance; but difficult to do reliably, so:
return prop.withValueDeserializer(unwrapping);
}
}
}
return null;
}
/**
* Helper method that will handle gruesome details of dealing with properties
* that have non-static inner class as value...
*/
protected SettableBeanProperty _resolveInnerClassValuedProperty(DeserializationContext ctxt,
SettableBeanProperty prop)
{
/* Should we encounter a property that has non-static inner-class
* as value, we need to add some more magic to find the "hidden" constructor...
*/
JsonDeserializer<Object> deser = prop.getValueDeserializer();
// ideally wouldn't rely on it being BeanDeserializerBase; but for now it'll have to do
if (deser instanceof BeanDeserializerBase) {
BeanDeserializerBase bd = (BeanDeserializerBase) deser;
ValueInstantiator vi = bd.getValueInstantiator();
if (!vi.canCreateUsingDefault()) { // no default constructor
Class<?> valueClass = prop.getType().getRawClass();
Class<?> enclosing = ClassUtil.getOuterClass(valueClass);
// and is inner class of the bean class...
if (enclosing != null && enclosing == _beanType.getRawClass()) {
for (Constructor<?> ctor : valueClass.getConstructors()) {
Class<?>[] paramTypes = ctor.getParameterTypes();
if (paramTypes.length == 1 && paramTypes[0] == enclosing) {
if (ctxt.canOverrideAccessModifiers()) {
ClassUtil.checkAndFixAccess(ctor, ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
}
return new Inner
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.databind.util.RawValue;
/**
* Interface that defines common "creator" functionality implemented
* both by {@link JsonNodeFactory} and {@link ContainerNode} (that is,
* JSON Object and Array nodes).
*
* @since 2.3
*/
public interface JsonNodeCreator
{
// Enumerated/singleton types
public ValueNode booleanNode(boolean v);
public ValueNode nullNode();
// Numeric types
public ValueNode numberNode(byte v);
public ValueNode numberNode(Byte value);
public ValueNode numberNode(short v);
public ValueNode numberNode(Short value);
public ValueNode numberNode(int v);
public ValueNode numberNode(Integer value);
public ValueNode numberNode(long v);
public ValueNode numberNode(Long value);
public ValueNode numberNode(BigInteger v);
public ValueNode numberNode(float v);
public ValueNode numberNode(Float value);
public ValueNode numberNode(double v);
public ValueNode numberNode(Double value);
public ValueNode numberNode(BigDecimal v);
// Textual nodes
public ValueNode textNode(String text);
// Other value (non-structured) nodes
public ValueNode binaryNode(byte[] data);
public ValueNode binaryNode(byte[] data, int offset, int length);
public ValueNode pojoNode(Object pojo);
/**
* Factory method to use for adding "raw values"; pre-encoded values
* that are included exactly as-is when node is serialized.
* This may be used, for example, to include fully serialized JSON
* sub-trees.
* Note that the concept may not work with all backends, and since
* no translation of any kinds is done it will not work when converting
* between data formats.
*
* @since 2.6
*/
public ValueNode rawValueNode(RawValue value);
// Structured nodes:
// (bit unkosher, due to forward references... but has to do for now)
public ArrayNode arrayNode();
public ObjectNode objectNode();
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> handle serialization of Dates used as {@link java.util.Map} keys,
* based on {@link SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS}
* value (and if using textual representation, configured date format)
*/
public void defaultSerializeDateKey(long timestamp, JsonGenerator gen) throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)) {
gen.writeFieldName(String.valueOf(timestamp));
} else {
gen.writeFieldName(_dateFormat().format(new Date(timestamp)));
}
}
/**
* Method that will handle serialization of Dates used as {@link java.util.Map} keys,
* based on {@link SerializationFeature#WRITE_DATE_KEYS_AS_TIMESTAMPS}
* value (and if using textual representation, configured date format)
*/
public void defaultSerializeDateKey(Date date, JsonGenerator gen) throws IOException
{
if (isEnabled(SerializationFeature.WRITE_DATE_KEYS_AS_TIMESTAMPS)) {
gen.writeFieldName(String.valueOf(date.getTime()));
} else {
gen.writeFieldName(_dateFormat().format(date));
}
}
public final void defaultSerializeNull(JsonGenerator jgen) throws IOException
{
if (_stdNullValueSerializer) { // minor perf optimization
jgen.writeNull();
} else {
_nullValueSerializer.serialize(null, jgen, this);
}
}
/*
/********************************************************
/* Error reporting
/********************************************************
*/
/**
* @since 2.6
*/
public JsonMappingException mappingException(String message, Object... args) {
if (args != null && args.length > 0) {
message = String.format(message, args);
}
return JsonMappingException.from(this, message);
}
/*
/********************************************************
/* Helper methods
/********************************************************
*/
protected void _reportIncompatibleRootType(Object value, JavaType rootType) throws IOException
{
// One special case: allow primitive/wrapper type coercion
if (rootType.isPrimitive()) {
Class<?> wrapperType = ClassUtil.wrapperType(rootType.getRawClass());
// If it's just difference between wrapper, primitive, let it slide
if (wrapperType.isAssignableFrom(value.getClass())) {
return;
}
}
throw JsonMappingException.from(this,
"Incompatible types: declared root type ("+rootType+") vs "
+value.getClass().getName());
}
/**
* Method that will try to
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> just use default format.
*/
protected final DateFormat _customFormat;
/**
* Let's also keep format String for reference, to use for error messages
*/
protected final String _formatString;
protected DateBasedDeserializer(Class<?> clz) {
super(clz);
_customFormat = null;
_formatString = null;
}
protected DateBasedDeserializer(DateBasedDeserializer<T> base,
DateFormat format, String formatStr) {
super(base._valueClass);
_customFormat = format;
_formatString = formatStr;
}
protected abstract DateBasedDeserializer<T> withDateFormat(DateFormat df, String formatStr);
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property)
throws JsonMappingException
{
if (property != null) {
JsonFormat.Value format = ctxt.getAnnotationIntrospector().findFormat((Annotated) property.getMember());
if (format != null) {
TimeZone tz = format.getTimeZone();
// First: fully custom pattern?
if (format.hasPattern()) {
final String pattern = format.getPattern();
final Locale loc = format.hasLocale() ? format.getLocale() : ctxt.getLocale();
SimpleDateFormat df = new SimpleDateFormat(pattern, loc);
if (tz == null) {
tz = ctxt.getTimeZone();
}
df.setTimeZone(tz);
return withDateFormat(df, pattern);
}
// But if not, can still override timezone
if (tz != null) {
DateFormat df = ctxt.getConfig().getDateFormat();
// one shortcut: with our custom format, can simplify handling a bit
if (df.getClass() == StdDateFormat.class) {
final Locale loc = format.hasLocale() ? format.getLocale() : ctxt.getLocale();
StdDateFormat std = (StdDateFormat) df;
std = std.withTimeZone(tz);
std = std.withLocale(loc);
df = std;
} else {
// otherwise need to clone, re-set timezone:
df = (DateFormat) df.clone();
df.setTimeZone(tz);
}
return withDateFormat(df, _formatString);
}
}
}
return this;
}
@Override
protected java.util.Date _parseDate(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_customFormat != null) {
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING) {
String str = p.getText().trim();
if (
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>str.length() == 0) {
return (Date) getEmptyValue(ctxt);
}
synchronized (_customFormat) {
try {
return _customFormat.parse(str);
} catch (ParseException e) {
throw new IllegalArgumentException("Failed to parse Date value '"+str
+"' (format: \""+_formatString+"\"): "+e.getMessage());
}
}
}
// [databind#381]
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Date parsed = _parseDate(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'java.util.Date' value but there was more than a single value in the array");
}
return parsed;
}
}
return super._parseDate(p, ctxt);
}
}
/*
/**********************************************************
/* Deserializer implementations for Date types
/**********************************************************
*/
@JacksonStdImpl
public static class CalendarDeserializer extends DateBasedDeserializer<Calendar>
{
/**
* We may know actual expected type; if so, it will be
* used for instantiation.
*/
protected final Class<? extends Calendar> _calendarClass;
public CalendarDeserializer() {
super(Calendar.class);
_calendarClass = null;
}
public CalendarDeserializer(Class<? extends Calendar> cc) {
super(cc);
_calendarClass = cc;
}
public CalendarDeserializer(CalendarDeserializer src, DateFormat df, String formatString) {
super(src, df, formatString);
_calendarClass = src._calendarClass;
}
@Override
protected CalendarDeserializer withDateFormat(DateFormat df, String formatString) {
return new CalendarDeserializer(this, df, formatString);
}
@Override
public Calendar deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
Date d = _parseDate(p, ctxt);
if (d == null) {
return null;
}
if (_calendarClass == null) {
return ctxt.constructCalendar(d);
}
try {
Calendar c = _calendarClass.newInstance();
c.setTimeInMillis(d.getTime());
TimeZone tz = ctxt.getTimeZone();
if (tz != null) {
c.setTimeZone(tz);
}
return c;
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.lang.reflect.TypeVariable;
import com.fasterxml.jackson.databind.JavaType;
/**
* Type that represents Java Collection types (Lists, Sets).
*/
public final class CollectionType
extends CollectionLikeType
{
private static final long serialVersionUID = 1L;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
private CollectionType(Class<?> collT, TypeBindings bindings,
JavaType superClass, JavaType[] superInts, JavaType elemT,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(collT, bindings, superClass, superInts, elemT, valueHandler, typeHandler, asStatic);
}
/**
* @since 2.7
*/
protected CollectionType(TypeBase base, JavaType elemT) {
super(base, elemT);
}
/**
* @since 2.7
*/
public static CollectionType construct(Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInts, JavaType elemT) {
return new CollectionType(rawType, bindings, superClass, superInts, elemT,
null, null, false);
}
/**
* @deprecated Since 2.7, remove from 2.8
*/
@Deprecated // since 2.7
public static CollectionType construct(Class<?> rawType, JavaType elemT) {
// First: may need to fabricate TypeBindings (needed for refining into
// concrete collection types, as per [databind#1102])
TypeVariable<?>[] vars = rawType.getTypeParameters();
TypeBindings bindings;
if ((vars == null) || (vars.length != 1)) {
bindings = TypeBindings.emptyBindings();
} else {
bindings = TypeBindings.create(rawType, elemT);
}
return new CollectionType(rawType, bindings,
// !!! TODO: Wrong, does have supertypes, but:
_bogusSuperClass(rawType), null, elemT,
null, null, false);
}
@Deprecated // since 2.7
@Override
protected JavaType _narrow(Class<?> subclass) {
return new CollectionType(subclass, _bindings,
_superClass, _superInterfaces, _elementType, null, null, _asStatic);
}
@Override
public JavaType withContentType(JavaType contentType) {
if (_elementType == contentType) {
return this;
}
return new CollectionType(_class, _bindings
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>.max(16, subtypes.length));
}
for (Class<?> subtype : subtypes) {
_subtypes.add(new NamedType(subtype));
}
return this;
}
/**
* Method for adding set of subtypes (along with type name to use) to be registered with
* {@link ObjectMapper}
* this is an alternative to using annotations in super type to indicate subtypes.
*/
public SimpleModule registerSubtypes(NamedType ... subtypes)
{
if (_subtypes == null) {
_subtypes = new LinkedHashSet<NamedType>(Math.max(16, subtypes.length));
}
for (NamedType subtype : subtypes) {
_subtypes.add(subtype);
}
return this;
}
/**
* Method for specifying that annotations define by <code>mixinClass</code>
* should be "mixed in" with annotations that <code>targetType</code>
* has (as if they were directly included on it!).
*<p>
* Mix-in annotations are
* registered when module is registered for <code>ObjectMapper</code>.
*/
public SimpleModule setMixInAnnotation(Class<?> targetType, Class<?> mixinClass)
{
if (_mixins == null) {
_mixins = new HashMap<Class<?>, Class<?>>();
}
_mixins.put(targetType, mixinClass);
return this;
}
/*
/**********************************************************
/* Module impl
/**********************************************************
*/
@Override
public String getModuleName() {
return _name;
}
/**
* Standard implementation handles registration of all configured
* customizations: it is important that sub-classes call this
* implementation (usually before additional custom logic)
* if they choose to override it; otherwise customizations
* will not be registered.
*/
@Override
public void setupModule(SetupContext context)
{
if (_serializers != null) {
context.addSerializers(_serializers);
}
if (_deserializers != null) {
context.addDeserializers(_deserializers);
}
if (_keySerializers != null) {
context.addKeySerializers(_keySerializers);
}
if (_keyDeserializers != null) {
context.addKeyDeserializers(_keyDeserializers);
}
if (_abstractTypes != null) {
context.addAbstractTypeResolver(_abstractTypes);
}
if (_valueInstantiators != null) {
context.addValueInstantiators(_valueInstantiators);
}
if (_deserializerModifier != null) {
context
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> = src._propertyBasedCreator;
_delegateDeserializer = src._delegateDeserializer;
_hasDefaultCreator = src._hasDefaultCreator;
_ignorableProperties = ignorable;
_standardStringKey = _isStdKeyDeser(_mapType, keyDeser);
}
/**
* Fluent factory method used to create a copy with slightly
* different settings. When sub-classing, MUST be overridden.
*/
@SuppressWarnings("unchecked")
protected MapDeserializer withResolved(KeyDeserializer keyDeser,
TypeDeserializer valueTypeDeser, JsonDeserializer<?> valueDeser,
HashSet<String> ignorable)
{
if ((_keyDeserializer == keyDeser) && (_valueDeserializer == valueDeser)
&& (_valueTypeDeserializer == valueTypeDeser) && (_ignorableProperties == ignorable)) {
return this;
}
return new MapDeserializer(this,
keyDeser, (JsonDeserializer<Object>) valueDeser, valueTypeDeser, ignorable);
}
/**
* Helper method used to check whether we can just use the default key
* deserialization, where JSON String becomes Java String.
*/
protected final boolean _isStdKeyDeser(JavaType mapType, KeyDeserializer keyDeser)
{
if (keyDeser == null) {
return true;
}
JavaType keyType = mapType.getKeyType();
if (keyType == null) { // assumed to be Object
return true;
}
Class<?> rawKeyType = keyType.getRawClass();
return ((rawKeyType == String.class || rawKeyType == Object.class)
&& isDefaultKeyDeserializer(keyDeser));
}
public void setIgnorableProperties(String[] ignorable) {
_ignorableProperties = (ignorable == null || ignorable.length == 0) ?
null : ArrayBuilders.arrayToSet(ignorable);
}
/*
/**********************************************************
/* Validation, post-processing (ResolvableDeserializer)
/**********************************************************
*/
@Override
public void resolve(DeserializationContext ctxt) throws JsonMappingException
{
// May need to resolve types for delegate- and/or property-based creators:
if (_valueInstantiator.canCreateUsingDelegate()) {
JavaType delegateType = _valueInstantiator.getDelegateType(ctxt.getConfig());
if (delegateType == null) {
throw new IllegalArgumentException("Invalid delegate-creator definition for "+_mapType
+": value instantiator ("+_valueInstantiator.getClass().getName()
+") returned true for 'canCreateUsingDelegate()', but null for 'getDelegateType()'");
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> }
/* Theoretically should be able to get CreatorProperty for delegate
* parameter to pass; but things get tricky because DelegateCreator
* may contain injectable values. So, for now, let's pass nothing.
*/
_delegateDeserializer = findDeserializer(ctxt, delegateType, null);
}
if (_valueInstantiator.canCreateFromObjectWith()) {
SettableBeanProperty[] creatorProps = _valueInstantiator.getFromObjectArguments(ctxt.getConfig());
_propertyBasedCreator = PropertyBasedCreator.construct(ctxt, _valueInstantiator, creatorProps);
}
_standardStringKey = _isStdKeyDeser(_mapType, _keyDeserializer);
}
/**
* Method called to finalize setup of this deserializer,
* when it is known for which property deserializer is needed for.
*/
@Override
public JsonDeserializer<?> createContextual(DeserializationContext ctxt,
BeanProperty property) throws JsonMappingException
{
KeyDeserializer kd = _keyDeserializer;
if (kd == null) {
kd = ctxt.findKeyDeserializer(_mapType.getKeyType(), property);
} else {
if (kd instanceof ContextualKeyDeserializer) {
kd = ((ContextualKeyDeserializer) kd).createContextual(ctxt, property);
}
}
JsonDeserializer<?> vd = _valueDeserializer;
// [databind#125]: May have a content converter
if (property != null) {
vd = findConvertingContentDeserializer(ctxt, property, vd);
}
final JavaType vt = _mapType.getContentType();
if (vd == null) {
vd = ctxt.findContextualValueDeserializer(vt, property);
} else { // if directly assigned, probably not yet contextual, so:
vd = ctxt.handleSecondaryContextualization(vd, property, vt);
}
TypeDeserializer vtd = _valueTypeDeserializer;
if (vtd != null) {
vtd = vtd.forProperty(property);
}
HashSet<String> ignored = _ignorableProperties;
AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
if (intr != null && property != null) {
AnnotatedMember member = property.getMember();
if (member != null) {
String[] moreToIgnore = intr.findPropertiesToIgnore(member, false);
if (moreToIgnore != null) {
ignored = (ignored == null) ? new HashSet<String>() : new HashSet<String>(ignored);
for (String str : moreToIgnore) {
ignored.add(str);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
gen.writeStartArray(len);
if (_serializer == null) {
serializeContents(value, gen, provider, len);
} else {
serializeUsingCustom(value, gen, provider, len);
}
gen.writeEndArray();
}
private final void _serializeUnwrapped(List<String> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
if (_serializer == null) {
serializeContents(value, gen, provider, 1);
} else {
serializeUsingCustom(value, gen, provider, 1);
}
}
@Override
public void serializeWithType(List<String> value, JsonGenerator gen,
SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
final int len = value.size();
typeSer.writeTypePrefixForArray(value, gen);
if (_serializer == null) {
serializeContents(value, gen, provider, len);
} else {
serializeUsingCustom(value, gen, provider, len);
}
typeSer.writeTypeSuffixForArray(value, gen);
}
private final void serializeContents(List<String> value, JsonGenerator gen,
SerializerProvider provider, int len) throws IOException
{
int i = 0;
try {
for (; i < len; ++i) {
String str = value.get(i);
if (str == null) {
provider.defaultSerializeNull(gen);
} else {
gen.writeString(str);
}
}
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
private final void serializeUsingCustom(List<String> value, JsonGenerator gen,
SerializerProvider provider, int len) throws IOException
{
int i = 0;
try {
final JsonSerializer<String> ser = _serializer;
for (i = 0; i < len; ++i) {
String str = value.get(i);
if (str == null) {
provider.defaultSerializeNull(gen);
} else {
ser.serialize(str, gen, provider);
}
}
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> null) {
serializeContents(value, gen, provider);
} else {
serializeUsingCustom(value, gen, provider);
}
gen.writeEndArray();
}
private final void _serializeUnwrapped(Collection<String> value, JsonGenerator gen,
SerializerProvider provider) throws IOException
{
if (_serializer == null) {
serializeContents(value, gen, provider);
} else {
serializeUsingCustom(value, gen, provider);
}
}
@Override
public void serializeWithType(Collection<String> value, JsonGenerator jgen, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonGenerationException
{
typeSer.writeTypePrefixForArray(value, jgen);
if (_serializer == null) {
serializeContents(value, jgen, provider);
} else {
serializeUsingCustom(value, jgen, provider);
}
typeSer.writeTypeSuffixForArray(value, jgen);
}
private final void serializeContents(Collection<String> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonGenerationException
{
if (_serializer != null) {
serializeUsingCustom(value, jgen, provider);
return;
}
int i = 0;
for (String str : value) {
try {
if (str == null) {
provider.defaultSerializeNull(jgen);
} else {
jgen.writeString(str);
}
++i;
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
}
private void serializeUsingCustom(Collection<String> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException, JsonGenerationException
{
final JsonSerializer<String> ser = _serializer;
int i = 0;
for (String str : value) {
try {
if (str == null) {
provider.defaultSerializeNull(jgen);
} else {
ser.serialize(str, jgen, provider);
}
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.io.IOException;
import java.util.*;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
public abstract class TypeBase
extends JavaType
implements JsonSerializable
{
private static final long serialVersionUID = 1;
private final static TypeBindings NO_BINDINGS = TypeBindings.emptyBindings();
private final static JavaType[] NO_TYPES = new JavaType[0];
protected final JavaType _superClass;
protected final JavaType[] _superInterfaces;
/**
* Bindings in effect for this type instance; possibly empty.
* Needed when resolving types declared in members of this type
* (if any).
*
* @since 2.7
*/
protected final TypeBindings _bindings;
/**
* Lazily initialized external representation of the type
*/
volatile transient String _canonicalName;
/**
* Main constructor to use by extending classes.
*/
protected TypeBase(Class<?> raw, TypeBindings bindings, JavaType superClass, JavaType[] superInts,
int hash,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(raw, hash, valueHandler, typeHandler, asStatic);
_bindings = (bindings == null) ? NO_BINDINGS : bindings;
_superClass = superClass;
_superInterfaces = superInts;
}
/**
* Copy-constructor used when refining/upgrading type instances.
*
* @since 2.7
*/
protected TypeBase(TypeBase base) {
super(base);
_superClass = base._superClass;
_superInterfaces = base._superInterfaces;
_bindings = base._bindings;
}
@Override
public String toCanonical()
{
String str = _canonicalName;
if (str == null) {
str = buildCanonicalName();
}
return str;
}
protected String buildCanonicalName() {
return _class.getName();
}
@Override
public abstract StringBuilder getGenericSignature(StringBuilder sb);
@Override
public abstract StringBuilder getErasedSignature(StringBuilder sb);
@Override
@SuppressWarnings("unchecked")
public <T> T getValueHandler() { return (T) _valueHandler; }
@Override
@SuppressWarnings("unchecked")
public <T> T getTypeHandler() { return (T) _typeHandler; }
@Override
public
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> TypeBindings getBindings() {
return _bindings;
}
@Override
public int containedTypeCount() {
return _bindings.size();
}
@Override
public JavaType containedType(int index) {
return _bindings.getBoundType(index);
}
@Override
@Deprecated
public String containedTypeName(int index) {
return _bindings.getBoundName(index);
}
@Override
public JavaType getSuperClass() {
return _superClass;
}
@Override
public List<JavaType> getInterfaces() {
if (_superInterfaces == null) {
return Collections.emptyList();
}
switch (_superInterfaces.length) {
case 0:
return Collections.emptyList();
case 1:
return Collections.singletonList(_superInterfaces[0]);
}
return Arrays.asList(_superInterfaces);
}
@Override
public final JavaType findSuperType(Class<?> rawTarget)
{
if (rawTarget == _class) {
return this;
}
// Check super interfaces first:
if (rawTarget.isInterface() && (_superInterfaces != null)) {
for (int i = 0, count = _superInterfaces.length; i < count; ++i) {
JavaType type = _superInterfaces[i].findSuperType(rawTarget);
if (type != null) {
return type;
}
}
}
// and if not found, super class and its supertypes
if (_superClass != null) {
JavaType type = _superClass.findSuperType(rawTarget);
if (type != null) {
return type;
}
}
return null;
}
@Override
public JavaType[] findTypeParameters(Class<?> expType)
{
JavaType match = findSuperType(expType);
if (match == null) {
return NO_TYPES;
}
return match.getBindings().typeParameterArray();
}
/*
/**********************************************************
/* JsonSerializable base implementation
/**********************************************************
*/
@Override
public void serializeWithType(JsonGenerator gen, SerializerProvider provider,
TypeSerializer typeSer)
throws IOException, JsonProcessingException
{
typeSer.writeTypePrefixForScalar(this, gen);
this.serialize(gen, provider);
typeSer.writeTypeSuffixForScalar(this, gen);
}
@Override
public void serialize(JsonGenerator gen, SerializerProvider provider)
throws IOException, JsonProcessingException
{
gen.writeString(toCanonical());
}
/*
/**********************************************************
/* Methods for sub
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>-classes to use
/**********************************************************
*/
/**
* @param trailingSemicolon Whether to add trailing semicolon for non-primitive
* (reference) types or not
*/
protected static StringBuilder _classSignature(Class<?> cls, StringBuilder sb,
boolean trailingSemicolon)
{
if (cls.isPrimitive()) {
if (cls == Boolean.TYPE) {
sb.append('Z');
} else if (cls == Byte.TYPE) {
sb.append('B');
}
else if (cls == Short.TYPE) {
sb.append('S');
}
else if (cls == Character.TYPE) {
sb.append('C');
}
else if (cls == Integer.TYPE) {
sb.append('I');
}
else if (cls == Long.TYPE) {
sb.append('J');
}
else if (cls == Float.TYPE) {
sb.append('F');
}
else if (cls == Double.TYPE) {
sb.append('D');
}
else if (cls == Void.TYPE) {
sb.append('V');
} else {
throw new IllegalStateException("Unrecognized primitive type: "+cls.getName());
}
} else {
sb.append('L');
String name = cls.getName();
for (int i = 0, len = name.length(); i < len; ++i) {
char c = name.charAt(i);
if (c == '.') c = '/';
sb.append(c);
}
if (trailingSemicolon) {
sb.append(';');
}
}
return sb;
}
/**
* Internal helper method used to figure out nominal super-class for
* deprecated factory methods / constructors, where we are not given
* properly resolved supertype hierarchy.
* Will basically give `JavaType` for `java.lang.Object` for classes
* other than `java.lafgn.Object`; null for others.
*
* @since 2.7
*/
protected static JavaType _bogusSuperClass(Class<?> cls) {
Class<?> parent = cls.getSuperclass();
if (parent == null) {
return null;
}
return TypeFactory.unknownType();
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> if (result == null) {
result = _secondary.isIgnorableType(ac);
}
return result;
}
@Override
public Object findFilterId(Annotated ann)
{
Object id = _primary.findFilterId(ann);
if (id == null) {
id = _secondary.findFilterId(ann);
}
return id;
}
@Override
public Object findNamingStrategy(AnnotatedClass ac)
{
Object str = _primary.findNamingStrategy(ac);
if (str == null) {
str = _secondary.findNamingStrategy(ac);
}
return str;
}
@Override
public String findClassDescription(AnnotatedClass ac) {
String str = _primary.findClassDescription(ac);
if ((str == null) || str.isEmpty()) {
str = _secondary.findClassDescription(ac);
}
return str;
}
/*
/******************************************************
/* Property auto-detection
/******************************************************
*/
@Override
public VisibilityChecker<?> findAutoDetectVisibility(AnnotatedClass ac,
VisibilityChecker<?> checker)
{
/* Note: to have proper priorities, we must actually call delegatees
* in reverse order:
*/
checker = _secondary.findAutoDetectVisibility(ac, checker);
return _primary.findAutoDetectVisibility(ac, checker);
}
/*
/******************************************************
/* Type handling
/******************************************************
*/
@Override
public TypeResolverBuilder<?> findTypeResolver(MapperConfig<?> config,
AnnotatedClass ac, JavaType baseType)
{
TypeResolverBuilder<?> b = _primary.findTypeResolver(config, ac, baseType);
if (b == null) {
b = _secondary.findTypeResolver(config, ac, baseType);
}
return b;
}
@Override
public TypeResolverBuilder<?> findPropertyTypeResolver(MapperConfig<?> config,
AnnotatedMember am, JavaType baseType)
{
TypeResolverBuilder<?> b = _primary.findPropertyTypeResolver(config, am, baseType);
if (b == null) {
b = _secondary.findPropertyTypeResolver(config, am, baseType);
}
return b;
}
@Override
public TypeResolverBuilder<?> findPropertyContentTypeResolver(MapperConfig<?> config,
AnnotatedMember am, JavaType baseType)
{
TypeResolverBuilder<?> b = _primary.findPropertyContentTypeResolver(config, am, baseType);
if (b == null) {
b = _secondary.findPropertyContentTypeResolver(config, am, baseType
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>);
}
return b;
}
@Override
public List<NamedType> findSubtypes(Annotated a)
{
List<NamedType> types1 = _primary.findSubtypes(a);
List<NamedType> types2 = _secondary.findSubtypes(a);
if (types1 == null || types1.isEmpty()) return types2;
if (types2 == null || types2.isEmpty()) return types1;
ArrayList<NamedType> result = new ArrayList<NamedType>(types1.size() + types2.size());
result.addAll(types1);
result.addAll(types2);
return result;
}
@Override
public String findTypeName(AnnotatedClass ac)
{
String name = _primary.findTypeName(ac);
if (name == null || name.length() == 0) {
name = _secondary.findTypeName(ac);
}
return name;
}
// // // General member (field, method/constructor) annotations
@Override
public ReferenceProperty findReferenceType(AnnotatedMember member) {
ReferenceProperty r = _primary.findReferenceType(member);
return (r == null) ? _secondary.findReferenceType(member) : r;
}
@Override
public NameTransformer findUnwrappingNameTransformer(AnnotatedMember member) {
NameTransformer r = _primary.findUnwrappingNameTransformer(member);
return (r == null) ? _secondary.findUnwrappingNameTransformer(member) : r;
}
@Override
public Object findInjectableValueId(AnnotatedMember m) {
Object r = _primary.findInjectableValueId(m);
return (r == null) ? _secondary.findInjectableValueId(m) : r;
}
@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
return _primary.hasIgnoreMarker(m) || _secondary.hasIgnoreMarker(m);
}
@Override
public Boolean hasRequiredMarker(AnnotatedMember m) {
Boolean r = _primary.hasRequiredMarker(m);
return (r == null) ? _secondary.hasRequiredMarker(m) : r;
}
// // // Serialization: general annotations
@Override
public Object findSerializer(Annotated am) {
Object r = _primary.findSerializer(am);
return _isExplicitClassOrOb(r, JsonSerializer.None.class)
? r : _secondary.findSerializer(am);
}
@Override
public Object findKeySerializer(Annotated a) {
Object r = _primary.findKeySerializer(a);
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>;
}
@Override
public Class<?>[] findViews(Annotated a) {
/* Theoretically this could be trickier, if multiple introspectors
* return non-null entries. For now, though, we'll just consider
* first one to return non-null to win.
*/
Class<?>[] result = _primary.findViews(a);
if (result == null) {
result = _secondary.findViews(a);
}
return result;
}
@Override
public Boolean isTypeId(AnnotatedMember member) {
Boolean b = _primary.isTypeId(member);
return (b == null) ? _secondary.isTypeId(member) : b;
}
@Override
public ObjectIdInfo findObjectIdInfo(Annotated ann) {
ObjectIdInfo r = _primary.findObjectIdInfo(ann);
return (r == null) ? _secondary.findObjectIdInfo(ann) : r;
}
@Override
public ObjectIdInfo findObjectReferenceInfo(Annotated ann, ObjectIdInfo objectIdInfo) {
// to give precedence for primary, must start with secondary:
objectIdInfo = _secondary.findObjectReferenceInfo(ann, objectIdInfo);
objectIdInfo = _primary.findObjectReferenceInfo(ann, objectIdInfo);
return objectIdInfo;
}
@Override
public JsonFormat.Value findFormat(Annotated ann) {
JsonFormat.Value v1 = _primary.findFormat(ann);
JsonFormat.Value v2 = _secondary.findFormat(ann);
if (v2 == null) { // shouldn't occur but just in case
return v1;
}
return v2.withOverrides(v1);
}
@Override
public PropertyName findWrapperName(Annotated ann) {
PropertyName name = _primary.findWrapperName(ann);
if (name == null) {
name = _secondary.findWrapperName(ann);
} else if (name == PropertyName.USE_DEFAULT) {
// does the other introspector have a better idea?
PropertyName name2 = _secondary.findWrapperName(ann);
if (name2 != null) {
name = name2;
}
}
return name;
}
@Override
public String findPropertyDefaultValue(Annotated ann) {
String str = _primary.findPropertyDefaultValue(ann);
return (str == null || str.isEmpty()) ? _secondary.findPropertyDefaultValue(ann) : str;
}
@Override
public String findPropertyDescription(Annotated ann) {
String r = _primary.findPropertyDescription(
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> SimpleType withContentValueHandler(Object h) {
// no content type, so:
throw new IllegalArgumentException("Simple types have no content types; can not call withContenValueHandler()");
}
@Override
public SimpleType withStaticTyping() {
return _asStatic ? this : new SimpleType(_class, _bindings,
_superClass, _superInterfaces, _valueHandler, _typeHandler, true);
}
@Override
public JavaType refine(Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces) {
// SimpleType means something not-specialized, so:
return null;
}
@Override
protected String buildCanonicalName()
{
StringBuilder sb = new StringBuilder();
sb.append(_class.getName());
final int count = _bindings.size();
if (count > 0) {
sb.append('<');
for (int i = 0; i < count; ++i) {
JavaType t = containedType(i);
if (i > 0) {
sb.append(',');
}
sb.append(t.toCanonical());
}
sb.append('>');
}
return sb.toString();
}
/*
/**********************************************************
/* Public API
/**********************************************************
*/
@Override
public boolean isContainerType() { return false; }
@Override
public StringBuilder getErasedSignature(StringBuilder sb) {
return _classSignature(_class, sb, true);
}
@Override
public StringBuilder getGenericSignature(StringBuilder sb)
{
_classSignature(_class, sb, false);
final int count = _bindings.size();
if (count > 0) {
sb.append('<');
for (int i = 0; i < count; ++i) {
sb = containedType(i).getGenericSignature(sb);
}
sb.append('>');
}
sb.append(';');
return sb;
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
/**
* Helper method we need to recursively build skeletal representations
* of superclasses.
*
* @since 2.7 -- remove when not needed (2.8?)
*/
private static JavaType _buildSuperClass(Class<?> superClass, TypeBindings b)
{
if (superClass == null) {
return null;
}
if (superClass == Object.class) {
return TypeFactory.unknownType();
}
JavaType superSuper = _buildSuperClass(superClass.getSuperclass
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> for collecting basic information on constructor(s) found
*/
protected void _addCreators(Map<String, POJOPropertyBuilder> props)
{
// can be null if annotation processing is disabled...
if (_annotationIntrospector != null) {
for (AnnotatedConstructor ctor : _classDef.getConstructors()) {
if (_creatorProperties == null) {
_creatorProperties = new LinkedList<POJOPropertyBuilder>();
}
for (int i = 0, len = ctor.getParameterCount(); i < len; ++i) {
_addCreatorParam(props, ctor.getParameter(i));
}
}
for (AnnotatedMethod factory : _classDef.getStaticMethods()) {
if (_creatorProperties == null) {
_creatorProperties = new LinkedList<POJOPropertyBuilder>();
}
for (int i = 0, len = factory.getParameterCount(); i < len; ++i) {
_addCreatorParam(props, factory.getParameter(i));
}
}
}
}
/**
* @since 2.4
*/
protected void _addCreatorParam(Map<String, POJOPropertyBuilder> props,
AnnotatedParameter param)
{
// JDK 8, paranamer, Scala can give implicit name
String impl = _annotationIntrospector.findImplicitPropertyName(param);
if (impl == null) {
impl = "";
}
PropertyName pn = _annotationIntrospector.findNameForDeserialization(param);
boolean expl = (pn != null && !pn.isEmpty());
if (!expl) {
if (impl.isEmpty()) {
/* Important: if neither implicit nor explicit name, can not make use
* of this creator parameter -- may or may not be a problem, verified
* at a later point.
*/
return;
}
// Also: if this occurs, there MUST be explicit annotation on creator itself
if (!_annotationIntrospector.hasCreatorAnnotation(param.getOwner())) {
return;
}
pn = PropertyName.construct(impl);
}
// shouldn't need to worry about @JsonIgnore, since creators only added
// if so annotated
/* 13-May-2015, tatu: We should try to start with implicit name, similar to how
* fields and methods work; but unlike those, we don't necessarily have
* implicit name to use (pre-Java8 at least). So:
*/
POJOPropertyBuilder prop = (expl && impl.isEmpty())
? _property(props, pn) : _property(props,
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> no way to force return type of "either class
* X or Y" -- need to throw an exception after the fact
*/
if (!(namingDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned PropertyNamingStrategy definition of type "
+namingDef.getClass().getName()+"; expected type PropertyNamingStrategy or Class<PropertyNamingStrategy> instead");
}
Class<?> namingClass = (Class<?>)namingDef;
// 09-Nov-2015, tatu: Need to consider pseudo-value of STD, which means "use default"
if (namingClass == PropertyNamingStrategy.class) {
return null;
}
if (!PropertyNamingStrategy.class.isAssignableFrom(namingClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "
+namingClass.getName()+"; expected Class<PropertyNamingStrategy>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
if (hi != null) {
PropertyNamingStrategy pns = hi.namingStrategyInstance(_config, _classDef, namingClass);
if (pns != null) {
return pns;
}
}
return (PropertyNamingStrategy) ClassUtil.createInstance(namingClass,
_config.canOverrideAccessModifiers());
}
protected void _updateCreatorProperty(POJOPropertyBuilder prop, List<POJOPropertyBuilder> creatorProperties) {
if (creatorProperties != null) {
for (int i = 0, len = creatorProperties.size(); i < len; ++i) {
if (creatorProperties.get(i).getInternalName().equals(prop.getInternalName())) {
creatorProperties.set(i, prop);
break;
}
}
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.lang.reflect.TypeVariable;
import java.util.Collection;
import com.fasterxml.jackson.databind.JavaType;
/**
* Type that represents things that act similar to {@link java.util.Collection};
* but may or may not be instances of that interface.
* This specifically allows framework to check for configuration and annotation
* settings used for Map types, and pass these to custom handlers that may be more
* familiar with actual type.
*/
public class CollectionLikeType extends TypeBase
{
private static final long serialVersionUID = 1L;
/**
* Type of elements in collection
*/
protected final JavaType _elementType;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
protected CollectionLikeType(Class<?> collT, TypeBindings bindings,
JavaType superClass, JavaType[] superInts, JavaType elemT,
Object valueHandler, Object typeHandler, boolean asStatic)
{
super(collT, bindings, superClass, superInts,
elemT.hashCode(), valueHandler, typeHandler, asStatic);
_elementType = elemT;
}
/**
* @since 2.7
*/
protected CollectionLikeType(TypeBase base, JavaType elemT)
{
super(base);
_elementType = elemT;
}
/**
* @since 2.7
*/
public static CollectionLikeType construct(Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInts, JavaType elemT) {
return new CollectionLikeType(rawType, bindings, superClass, superInts, elemT,
null, null, false);
}
/**
* @deprecated Since 2.7, use {@link #upgradeFrom} for constructing instances, given
* pre-resolved {@link SimpleType}.
*/
@Deprecated // since 2.7
public static CollectionLikeType construct(Class<?> rawType, JavaType elemT) {
// First: may need to fabricate TypeBindings (needed for refining into
// concrete collection types, as per [databind#1102])
TypeVariable<?>[] vars = rawType.getTypeParameters();
TypeBindings bindings;
if ((vars == null) || (vars.length != 1)) {
bindings = TypeBindings.emptyBindings();
} else {
bindings = TypeBindings.create(rawType, elemT);
}
return new CollectionLikeType(rawType, bindings,
_bogusSuperClass(rawType), null,
elemT, null
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> public void testLongToBoolean() throws Exception
{
long value = 1L + Integer.MAX_VALUE;
BooleanBean b = MAPPER.readValue("{\"primitive\" : "+value+", \"wrapper\":"+value+", \"ctor\":"+value+"}",
BooleanBean.class);
assertEquals(Boolean.TRUE, b.wrapper);
assertTrue(b.primitive);
assertEquals(Boolean.TRUE, b.ctor);
}
// [JACKSON-789]
public void testCharset() throws Exception
{
Charset UTF8 = Charset.forName("UTF-8");
assertSame(UTF8, MAPPER.readValue(quote("UTF-8"), Charset.class));
}
// [JACKSON-888]
public void testStackTraceElement() throws Exception
{
StackTraceElement elem = null;
try {
throw new IllegalStateException();
} catch (Exception e) {
elem = e.getStackTrace()[0];
}
String json = MAPPER.writeValueAsString(elem);
StackTraceElement back = MAPPER.readValue(json, StackTraceElement.class);
assertEquals("testStackTraceElement", back.getMethodName());
assertEquals(elem.getLineNumber(), back.getLineNumber());
assertEquals(elem.getClassName(), back.getClassName());
assertEquals(elem.isNativeMethod(), back.isNativeMethod());
assertTrue(back.getClassName().endsWith("TestJdkTypes"));
assertFalse(back.isNativeMethod());
}
// [Issue#239]
public void testByteBuffer() throws Exception
{
byte[] INPUT = new byte[] { 1, 3, 9, -1, 6 };
String exp = MAPPER.writeValueAsString(INPUT);
ByteBuffer result = MAPPER.readValue(exp, ByteBuffer.class);
assertNotNull(result);
assertEquals(INPUT.length, result.remaining());
for (int i = 0; i < INPUT.length; ++i) {
assertEquals(INPUT[i], result.get());
}
assertEquals(0, result.remaining());
}
public void testStringBuilder() throws Exception
{
StringBuilder sb = MAPPER.readValue(quote("abc"), StringBuilder.class);
assertEquals("abc", sb.toString());
}
// [Issue#429]
public void testStackTraceElementWithCustom() throws Exception
{
// first, via bean that contains StackTraceElement
StackTraceBean bean = MAPPER.readValue(aposToQuotes("{'Location':'foobar'}"),
StackTraceBean.class);
assertNotNull(bean);
assertNotNull(bean.location);
assertEquals(StackTrace
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Bean.NUM, bean.location.getLineNumber());
// and then directly, iff registered
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addDeserializer(StackTraceElement.class, new MyStackTraceElementDeserializer());
mapper.registerModule(module);
StackTraceElement elem = mapper.readValue("123", StackTraceElement.class);
assertNotNull(elem);
assertEquals(StackTraceBean.NUM, elem.getLineNumber());
// and finally, even as part of real exception
IOException ioe = mapper.readValue(aposToQuotes("{'stackTrace':[ 123, 456 ]}"),
IOException.class);
assertNotNull(ioe);
StackTraceElement[] traces = ioe.getStackTrace();
assertNotNull(traces);
assertEquals(2, traces.length);
assertEquals(StackTraceBean.NUM, traces[0].getLineNumber());
assertEquals(StackTraceBean.NUM, traces[1].getLineNumber());
}
/*
/**********************************************************
/* Single-array handling tests
/**********************************************************
*/
// [Issue#381]
public void testSingleElementArray() throws Exception {
final int intTest = 932832;
final double doubleTest = 32.3234;
final long longTest = 2374237428374293423L;
final short shortTest = (short) intTest;
final float floatTest = 84.3743f;
final byte byteTest = (byte) 43;
final char charTest = 'c';
final ObjectMapper mapper = new ObjectMapper();
mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);
final int intValue = mapper.readValue(asArray(intTest), Integer.TYPE);
assertEquals(intTest, intValue);
final Integer integerWrapperValue = mapper.readValue(asArray(Integer.valueOf(intTest)), Integer.class);
assertEquals(Integer.valueOf(intTest), integerWrapperValue);
final double doubleValue = mapper.readValue(asArray(doubleTest), Double.class);
assertEquals(doubleTest, doubleValue);
final Double doubleWrapperValue = mapper.readValue(asArray(Double.valueOf(doubleTest)), Double.class);
assertEquals(Double.valueOf(doubleTest), doubleWrapperValue);
final long longValue = mapper.readValue(asArray(longTest), Long.TYPE);
assertEquals(longTest, longValue);
final Long longWrapperValue = mapper.readValue(asArray(Long.valueOf(longTest
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>)), Long.class);
assertEquals(Long.valueOf(longTest), longWrapperValue);
final short shortValue = mapper.readValue(asArray(shortTest), Short.TYPE);
assertEquals(shortTest, shortValue);
final Short shortWrapperValue = mapper.readValue(asArray(Short.valueOf(shortTest)), Short.class);
assertEquals(Short.valueOf(shortTest), shortWrapperValue);
final float floatValue = mapper.readValue(asArray(floatTest), Float.TYPE);
assertEquals(floatTest, floatValue);
final Float floatWrapperValue = mapper.readValue(asArray(Float.valueOf(floatTest)), Float.class);
assertEquals(Float.valueOf(floatTest), floatWrapperValue);
final byte byteValue = mapper.readValue(asArray(byteTest), Byte.TYPE);
assertEquals(byteTest, byteValue);
final Byte byteWrapperValue = mapper.readValue(asArray(Byte.valueOf(byteTest)), Byte.class);
assertEquals(Byte.valueOf(byteTest), byteWrapperValue);
final char charValue = mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.TYPE);
assertEquals(charTest, charValue);
final Character charWrapperValue = mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.class);
assertEquals(Character.valueOf(charTest), charWrapperValue);
final boolean booleanTrueValue = mapper.readValue(asArray(true), Boolean.TYPE);
assertTrue(booleanTrueValue);
final boolean booleanFalseValue = mapper.readValue(asArray(false), Boolean.TYPE);
assertFalse(booleanFalseValue);
final Boolean booleanWrapperTrueValue = mapper.readValue(asArray(Boolean.valueOf(true)), Boolean.class);
assertEquals(Boolean.TRUE, booleanWrapperTrueValue);
}
private static String asArray(Object value) {
final String stringVal = value.toString();
return new StringBuilder(stringVal.length() + 2).append("[").append(stringVal).append("]").toString();
}
public void testSingleElementArrayException() throws Exception {
final ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);
try {
mapper.readValue("[42]", Integer.class);
fail("Single value array didn't throw an exception when DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS is disabled");
} catch (JsonMappingException exp) {
//Exception was thrown correctly
}
try {
mapper.readValue("[42]", Integer.TYPE);
fail("Single value array didn't throw an
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>subclass == HashSet.class)
|| (subclass == TreeSet.class)) {
newType = _fromClass(null, subclass,
TypeBindings.create(subclass, baseType.getContentType()));
break;
}
// 29-Oct-2015, tatu: One further shortcut: there are variants of `EnumSet`,
// but they are impl details and we basically do not care...
if (rawBase == EnumSet.class) {
return baseType;
}
}
}
// (3) Sub-class does not take type parameters -- just resolve subtype
int typeParamCount = subclass.getTypeParameters().length;
if (typeParamCount == 0) {
newType = _fromClass(null, subclass, TypeBindings.emptyBindings());
break;
}
// If not, we'll need to do more thorough forward+backwards resolution. Sigh.
// !!! TODO (as of 28-Jan-2016, at least)
// 20-Oct-2015, tatu: Container, Map-types somewhat special. There is
// a way to fully resolve and merge hierarchies; but that gets expensive
// so let's, for now, try to create close-enough approximation that
// is not 100% same, structurally, but has equivalent information for
// our specific neeeds.
// 29-Mar-2016, tatu: See [databind#1173] (and test `TypeResolverTest`)
// for a case where this code does get invoked: not ideal
// 29-Jun-2016, tatu: As to bindings, this works for [databind#1215], but
// not certain it would reliably work... but let's hope for best for now
TypeBindings tb = _bindingsForSubtype(baseType, typeParamCount, subclass);
if (baseType.isInterface()) {
newType = baseType.refine(subclass, tb, null, new JavaType[] { baseType });
} else {
newType = baseType.refine(subclass, tb, baseType, NO_TYPES);
}
// Only SimpleType returns null, but if so just resolve regularly
if (newType == null) {
newType = _fromClass(null, subclass, tb);
}
} while (false);
// except possibly handlers
// newType = newType.withHandlersFrom(baseType);
return newType
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>;
// 20-Oct-2015, tatu: Old simplistic approach
/*
// Currently mostly SimpleType instances can become something else
if (baseType instanceof SimpleType) {
// and only if subclass is an array, Collection or Map
if (subclass.isArray()
|| Map.class.isAssignableFrom(subclass)
|| Collection.class.isAssignableFrom(subclass)) {
// need to assert type compatibility...
if (!baseType.getRawClass().isAssignableFrom(subclass)) {
throw new IllegalArgumentException("Class "+subclass.getClass().getName()+" not subtype of "+baseType);
}
// this _should_ work, right?
JavaType subtype = _fromClass(null, subclass, TypeBindings.emptyBindings());
// one more thing: handlers to copy?
Object h = baseType.getValueHandler();
if (h != null) {
subtype = subtype.withValueHandler(h);
}
h = baseType.getTypeHandler();
if (h != null) {
subtype = subtype.withTypeHandler(h);
}
return subtype;
}
}
// But there is the need for special case for arrays too, it seems
if (baseType instanceof ArrayType) {
if (subclass.isArray()) {
// actually see if it might be a no-op first:
ArrayType at = (ArrayType) baseType;
Class<?> rawComp = subclass.getComponentType();
if (at.getContentType().getRawClass() == rawComp) {
return baseType;
}
JavaType componentType = _fromAny(null, rawComp, null);
return ((ArrayType) baseType).withComponentType(componentType);
}
}
// otherwise regular narrowing should work just fine
return baseType.narrowBy(subclass);
*/
}
private TypeBindings _bindingsForSubtype(JavaType baseType, int typeParamCount, Class<?> subclass)
{
// But otherwise gets bit tricky, as we need to partially resolve the type hierarchy
// (hopefully passing null Class for root is ok)
int baseCount = baseType.containedTypeCount();
if (baseCount == typeParamCount) {
if (typeParamCount == 1) {
return TypeBindings.create(subclass, baseType.containedType(0));
}
if (typeParamCount == 2) {
return TypeBindings.create(subclass, baseType.containedType(0),
baseType.containedType(1));
}
List<JavaType> types = new ArrayList<JavaType>(baseCount);
for (int i = 0; i
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> < baseCount; ++i) {
types.add(baseType.containedType(i));
}
return TypeBindings.create(subclass, types);
}
// Otherwise, two choices: match N first, or empty. Do latter, for now
return TypeBindings.emptyBindings();
}
/**
* Method similar to {@link #constructSpecializedType}, but that creates a
* less-specific type of given type. Usually this is as simple as simply
* finding super-type with type erasure of <code>superClass</code>, but
* there may be need for some additional work-arounds.
*
* @param superClass
*
* @since 2.7
*/
public JavaType constructGeneralizedType(JavaType baseType, Class<?> superClass)
{
// simple optimization to avoid costly introspection if type-erased type does NOT differ
final Class<?> rawBase = baseType.getRawClass();
if (rawBase == superClass) {
return baseType;
}
JavaType superType = baseType.findSuperType(superClass);
if (superType == null) {
// Most likely, caller did not verify sub/super-type relationship
if (!superClass.isAssignableFrom(rawBase)) {
throw new IllegalArgumentException(String.format(
"Class %s not a super-type of %s", superClass.getName(), baseType));
}
// 01-Nov-2015, tatu: Should never happen, but ch
throw new IllegalArgumentException(String.format(
"Internal error: class %s not included as super-type for %s",
superClass.getName(), baseType));
}
return superType;
}
/**
* Factory method for constructing a {@link JavaType} out of its canonical
* representation (see {@link JavaType#toCanonical()}).
*
* @param canonical Canonical string representation of a type
*
* @throws IllegalArgumentException If canonical representation is malformed,
* or class that type represents (including its generic parameters) is
* not found
*/
public JavaType constructFromCanonical(String canonical) throws IllegalArgumentException
{
return _parser.parse(canonical);
}
/**
* Method that is to figure out actual type parameters that given
* class binds to generic types defined by given (generic)
* interface or class.
* This could mean, for example, trying to figure out
* key and value types for Map implementations.
*
* @param type Sub-type (leaf type) that implements <code>expType</code>
*/
public
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
{
return constructSimpleType(rawType, parameterTypes);
}
/**
* @since 2.6
*/
public JavaType constructReferenceType(Class<?> rawType, JavaType referredType)
{
return ReferenceType.construct(rawType, null, // no bindings
null, null, // or super-class, interfaces?
referredType);
}
/**
* Method that will force construction of a simple type, without trying to
* check for more specialized types.
*<p>
* NOTE: no type modifiers are called on type either, so calling this method
* should only be used if caller really knows what it's doing...
*/
public JavaType uncheckedSimpleType(Class<?> cls) {
// 18-Oct-2015, tatu: Not sure how much problem missing super-type info is here
return _constructSimple(cls, EMPTY_BINDINGS, null, null);
}
/**
* Factory method for constructing {@link JavaType} that
* represents a parameterized type. For example, to represent
* type <code>List<Set<Integer>></code>, you could
* call
*<pre>
* JavaType inner = TypeFactory.constructParametrizedType(Set.class, Set.class, Integer.class);
* return TypeFactory.constructParametrizedType(ArrayList.class, List.class, inner);
*</pre>
*<p>
* The reason for first two arguments to be separate is that parameterization may
* apply to a super-type. For example, if generic type was instead to be
* constructed for <code>ArrayList<Integer></code>, the usual call would be:
*<pre>
* TypeFactory.constructParametrizedType(ArrayList.class, List.class, Integer.class);
*</pre>
* since parameterization is applied to {@link java.util.List}.
* In most cases distinction does not matter, but there are types where it does;
* one such example is parameterization of types that implement {@link java.util.Iterator}.
*<p>
* NOTE: type modifiers are NOT called on constructed type.
*
* @param parametrized Actual full type
* @param parameterClasses Type parameters to apply
*
* @since 2.5 NOTE: was briefly deprecated for 2.6
*/
public JavaType constructParametricType(Class<?> parametrized, Class<?>... parameterClasses) {
int len = parameterClasses.length;
JavaType[] pt
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> = new JavaType[len];
for (int i = 0; i < len; ++i) {
pt[i] = _fromClass(null, parameterClasses[i], null);
}
return constructParametricType(parametrized, pt);
}
/**
* Factory method for constructing {@link JavaType} that
* represents a parameterized type. For example, to represent
* type <code>List<Set<Integer>></code>, you could
* call
*<pre>
* JavaType inner = TypeFactory.constructParametrizedType(Set.class, Set.class, Integer.class);
* return TypeFactory.constructParametrizedType(ArrayList.class, List.class, inner);
*</pre>
*<p>
* The reason for first two arguments to be separate is that parameterization may
* apply to a super-type. For example, if generic type was instead to be
* constructed for <code>ArrayList<Integer></code>, the usual call would be:
*<pre>
* TypeFactory.constructParametrizedType(ArrayList.class, List.class, Integer.class);
*</pre>
* since parameterization is applied to {@link java.util.List}.
* In most cases distinction does not matter, but there are types where it does;
* one such example is parameterization of types that implement {@link java.util.Iterator}.
*<p>
* NOTE: type modifiers are NOT called on constructed type.
*
* @param rawType Actual type-erased type
* @param parameterTypes Type parameters to apply
*
* @since 2.5 NOTE: was briefly deprecated for 2.6
*/
public JavaType constructParametricType(Class<?> rawType, JavaType... parameterTypes)
{
return _fromClass(null, rawType, TypeBindings.create(rawType, parameterTypes));
}
/**
* @since 2.5 -- but will probably deprecated in 2.7 or 2.8 (not needed with 2.7)
*/
public JavaType constructParametrizedType(Class<?> parametrized, Class<?> parametersFor,
JavaType... parameterTypes)
{
return constructParametricType(parametrized, parameterTypes);
}
/**
* @since 2.5 -- but will probably deprecated in 2.7 or 2.8 (not needed with 2.7)
*/
public JavaType constructParametrizedType(Class<?> parametrized, Class<?>
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>_STRING);
}
// And then check what flavor of type we got. Start by asking resolved
// super-type if refinement is all that is needed?
else if (superClass != null) {
result = superClass.refine(rawType, bindings, superClass, superInterfaces);
}
// if not, perhaps we are now resolving a well-known class or interface?
if (result == null) {
result = _fromWellKnownClass(context, rawType, bindings, superClass, superInterfaces);
if (result == null) {
result = _fromWellKnownInterface(context, rawType, bindings, superClass, superInterfaces);
if (result == null) {
// but if nothing else, "simple" class for now:
result = _newSimpleType(rawType, bindings, superClass, superInterfaces);
}
}
}
}
context.resolveSelfReferences(result);
if (key != null) {
_typeCache.putIfAbsent(key, result); // cache object syncs
}
return result;
}
protected JavaType _resolveSuperClass(ClassStack context, Class<?> rawType, TypeBindings parentBindings)
{
Type parent = ClassUtil.getGenericSuperclass(rawType);
if (parent == null) {
return null;
}
return _fromAny(context, parent, parentBindings);
}
protected JavaType[] _resolveSuperInterfaces(ClassStack context, Class<?> rawType, TypeBindings parentBindings)
{
Type[] types = ClassUtil.getGenericInterfaces(rawType);
if (types == null || types.length == 0) {
return NO_TYPES;
}
int len = types.length;
JavaType[] resolved = new JavaType[len];
for (int i = 0; i < len; ++i) {
Type type = types[i];
resolved[i] = _fromAny(context, type, parentBindings);
}
return resolved;
}
/**
* Helper class used to check whether exact class for which type is being constructed
* is one of well-known base interfaces or classes that indicates alternate
* {@link JavaType} implementation.
*/
protected JavaType _fromWellKnownClass(ClassStack context, Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces)
{
// Quite simple when we resolving exact class/interface; start with that
if (rawType == Map.class) {
return _mapType(rawType, bindings, superClass, superInterfaces);
}
if (rawType
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> == Collection.class) {
return _collectionType(rawType, bindings, superClass, superInterfaces);
}
// and since 2.6 one referential type
if (rawType == AtomicReference.class) {
return _referenceType(rawType, bindings, superClass, superInterfaces);
}
// 01-Nov-2015, tatu: As of 2.7, couple of potential `CollectionLikeType`s (like
// `Iterable`, `Iterator`), and `MapLikeType`s (`Map.Entry`) are not automatically
// detected, related to difficulties in propagating type upwards (Iterable, for
// example, is a weak, tag-on type). They may be detectable in future.
return null;
}
protected JavaType _fromWellKnownInterface(ClassStack context, Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces)
{
// But that's not all: may be possible current type actually implements an
// interface type. So...
final int intCount = superInterfaces.length;
for (int i = 0; i < intCount; ++i) {
JavaType result = superInterfaces[i].refine(rawType, bindings, superClass, superInterfaces);
if (result != null) {
return result;
}
}
return null;
}
/**
* This method deals with parameterized types, that is,
* first class generic classes.
*/
protected JavaType _fromParamType(ClassStack context, ParameterizedType ptype,
TypeBindings parentBindings)
{
// Assumption here is we'll always get Class, not one of other Types
Class<?> rawType = (Class<?>) ptype.getRawType();
// 29-Oct-2015, tatu: For performance reasons, let's streamline handling of
// couple of not-so-useful parametric types
if (rawType == CLS_ENUM) {
return CORE_TYPE_ENUM;
}
if (rawType == CLS_COMPARABLE) {
return CORE_TYPE_COMPARABLE;
}
if (rawType == CLS_CLASS) {
return CORE_TYPE_CLASS;
}
// First: what is the actual base type? One odd thing is that 'getRawType'
// returns Type, not Class<?> as one might expect. But let's assume it is
// always of type Class: if not, need to add more code to resolve it to Class.
Type[] args = ptype.
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>getActualTypeArguments();
int paramCount = (args == null) ? 0 : args.length;
JavaType[] pt;
TypeBindings newBindings;
if (paramCount == 0) {
newBindings = EMPTY_BINDINGS;
} else {
pt = new JavaType[paramCount];
for (int i = 0; i < paramCount; ++i) {
pt[i] = _fromAny(context, args[i], parentBindings);
}
newBindings = TypeBindings.create(rawType, pt);
}
return _fromClass(context, rawType, newBindings);
}
protected JavaType _fromArrayType(ClassStack context, GenericArrayType type, TypeBindings bindings)
{
JavaType elementType = _fromAny(context, type.getGenericComponentType(), bindings);
return ArrayType.construct(elementType, bindings);
}
protected JavaType _fromVariable(ClassStack context, TypeVariable<?> var, TypeBindings bindings)
{
// ideally should find it via bindings:
final String name = var.getName();
JavaType type = bindings.findBoundType(name);
if (type != null) {
return type;
}
// but if not, use bounds... note that approach here is simplistic; not taking
// into account possible multiple bounds, nor consider upper bounds.
if (bindings.hasUnbound(name)) {
return CORE_TYPE_OBJECT;
}
bindings = bindings.withUnboundVariable(name);
Type[] bounds = var.getBounds();
return _fromAny(context, bounds[0], bindings);
}
protected JavaType _fromWildcard(ClassStack context, WildcardType type, TypeBindings bindings)
{
/* Similar to challenges with TypeVariable, we may have multiple upper bounds.
* But it is also possible that if upper bound defaults to Object, we might
* want to consider lower bounds instead.
* For now, we won't try anything more advanced; above is just for future reference.
*/
return _fromAny(context, type.getUpperBounds()[0], bindings);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> serializers after
* configuration changes for mapper than owns the provider.
*/
public void flushCachedSerializers() {
_serializerCache.flush();
}
/*
/**********************************************************
/* Object Id handling
/**********************************************************
*/
@Override
public WritableObjectId findObjectId(Object forPojo, ObjectIdGenerator<?> generatorType)
{
if (_seenObjectIds == null) {
_seenObjectIds = _createObjectIdMap();
} else {
WritableObjectId oid = _seenObjectIds.get(forPojo);
if (oid != null) {
return oid;
}
}
// Not seen yet; must add an entry, return it. For that, we need generator
ObjectIdGenerator<?> generator = null;
if (_objectIdGenerators == null) {
_objectIdGenerators = new ArrayList<ObjectIdGenerator<?>>(8);
} else {
for (int i = 0, len = _objectIdGenerators.size(); i < len; ++i) {
ObjectIdGenerator<?> gen = _objectIdGenerators.get(i);
if (gen.canUseFor(generatorType)) {
generator = gen;
break;
}
}
}
if (generator == null) {
generator = generatorType.newForSerialization(this);
_objectIdGenerators.add(generator);
}
WritableObjectId oid = new WritableObjectId(generator);
_seenObjectIds.put(forPojo, oid);
return oid;
}
/**
* Overridable helper method used for creating {@link java.util.Map}
* used for storing mappings from serializable objects to their
* Object Ids.
*
* @since 2.3
*/
protected Map<Object,WritableObjectId> _createObjectIdMap()
{
/* 06-Aug-2013, tatu: We may actually want to use equality,
* instead of identity... so:
*/
if (isEnabled(SerializationFeature.USE_EQUALITY_FOR_OBJECT_ID)) {
return new HashMap<Object,WritableObjectId>();
}
return new IdentityHashMap<Object,WritableObjectId>();
}
/*
/**********************************************************
/* Factory method impls
/**********************************************************
*/
@Override
public JsonSerializer<Object> serializerInstance(Annotated annotated, Object serDef) throws JsonMappingException
{
if (serDef == null) {
return null;
}
JsonSerializer<?> ser;
if (serDef instanceof JsonSerializer) {
ser = (JsonSerializer<?>) serDef;
} else {
/* Alas, there's no way to force return type of "
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> method may return null .
*/
public AnnotatedWithParams getArrayDelegateCreator() { return null; }
/**
* Method that can be called to try to access member (constructor,
* static factory method) that is used as the "non-default creator"
* (constructor or factory method that takes one or more arguments).
* Note that implementations not required to return actual object
* they use (or, they may use some other instantiation) method.
* That is, even if {@link #canCreateFromObjectWith()} returns true,
* this method may return null .
*/
public AnnotatedWithParams getWithArgsCreator() { return null; }
/**
* If an incomplete creator was found, this is the first parameter that
* needs further annotation to help make the creator complete.
*/
public AnnotatedParameter getIncompleteParameter() { return null; }
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
/**
* @since 2.4 (demoted from <code>StdValueInstantiator</code>)
*/
protected Object _createFromStringFallbacks(DeserializationContext ctxt, String value)
throws IOException, JsonProcessingException
{
/* 28-Sep-2011, tatu: Ok this is not clean at all; but since there are legacy
* systems that expect conversions in some cases, let's just add a minimal
* patch (note: same could conceivably be used for numbers too).
*/
if (canCreateFromBoolean()) {
String str = value.trim();
if ("true".equals(str)) {
return createFromBoolean(ctxt, true);
}
if ("false".equals(str)) {
return createFromBoolean(ctxt, false);
}
}
// also, empty Strings might be accepted as null Object...
if (value.length() == 0) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
return null;
}
}
throw ctxt.mappingException("Can not instantiate value of type %s from String value ('%s'); no single-String constructor/factory method",
getValueTypeDesc(), value);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> _method.getReturnType();
}
@Deprecated
@Override
public Type getGenericType() {
return _method.getGenericReturnType();
}
/*
/*****************************************************
/* AnnotatedWithParams
/*****************************************************
*/
@Override
public final Object call() throws Exception {
return _method.invoke(null);
}
@Override
public final Object call(Object[] args) throws Exception {
return _method.invoke(null, args);
}
@Override
public final Object call1(Object arg) throws Exception {
return _method.invoke(null, arg);
}
/*
/********************************************************
/* AnnotatedMember impl
/********************************************************
*/
@Override
public int getParameterCount() {
return getRawParameterTypes().length;
}
@Override
public Class<?> getRawParameterType(int index)
{
Class<?>[] types = getRawParameterTypes();
return (index >= types.length) ? null : types[index];
}
@Override
public JavaType getParameterType(int index) {
Type[] types = _method.getGenericParameterTypes();
if (index >= types.length) {
return null;
}
return _typeContext.resolveType(types[index]);
}
@Override
@Deprecated // since 2.7
public Type getGenericParameterType(int index) {
Type[] types = getGenericParameterTypes();
if (index >= types.length) {
return null;
}
return types[index];
}
@Override
public Class<?> getDeclaringClass() { return _method.getDeclaringClass(); }
@Override
public Method getMember() { return _method; }
@Override
public void setValue(Object pojo, Object value) throws IllegalArgumentException
{
try {
_method.invoke(pojo, value);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to setValue() with method "
+getFullName()+": "+e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("Failed to setValue() with method "
+getFullName()+": "+e.getMessage(), e);
}
}
@Override
public Object getValue(Object pojo) throws IllegalArgumentException
{
try {
return _method.invoke(pojo);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Failed to getValue() with method "
+getFullName()+": "+e.getMessage(), e);
} catch (InvocationTargetException e) {
throw new IllegalArgumentException("Failed to getValue() with method "
+getFullName()+": "+e.getMessage(),
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
*/
@Override
public ValueNode numberNode(Double value) {
return (value == null) ? nullNode() : DoubleNode.valueOf(value.doubleValue());
}
/**
* Factory method for getting an instance of JSON numeric value
* that expresses given unlimited precision floating point value
*
* <p>In the event that the factory has been built to normalize decimal
* values, the BigDecimal argument will be stripped off its trailing zeroes,
* using {@link BigDecimal#stripTrailingZeros()}.</p>
*
* @see #JsonNodeFactory(boolean)
*/
@Override
public NumericNode numberNode(BigDecimal v)
{
/*
* If the user wants the exact representation of this big decimal,
* return the value directly
*/
if (_cfgBigDecimalExact)
return DecimalNode.valueOf(v);
/*
* If the user has asked to strip trailing zeroes, however, there is
* this bug to account for:
*
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6480539
*
* In short: zeroes are never stripped out of 0! We therefore _have_
* to compare with BigDecimal.ZERO...
*/
return v.compareTo(BigDecimal.ZERO) == 0 ? DecimalNode.ZERO
: DecimalNode.valueOf(v.stripTrailingZeros());
}
/*
/**********************************************************
/* Factory methods for textual values
/**********************************************************
*/
/**
* Factory method for constructing a node that represents JSON
* String value
*/
@Override
public TextNode textNode(String text) { return TextNode.valueOf(text); }
/**
* Factory method for constructing a node that represents given
* binary data, and will get serialized as equivalent base64-encoded
* String value
*/
@Override
public BinaryNode binaryNode(byte[] data) { return BinaryNode.valueOf(data); }
/**
* Factory method for constructing a node that represents given
* binary data, and will get serialized as equivalent base64-encoded
* String value
*/
@Override
public BinaryNode binaryNode(byte[] data, int offset, int length) {
return BinaryNode.valueOf(data, offset, length);
}
/*
/**********************************************************
/* Factory method for structured values
/**********************************************************
*/
/**
* Factory method for constructing an empty JSON Array node
*/
@Override
public ArrayNode arrayNode() { return new ArrayNode(this); }
/**
* Factory method for constructing an empty
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> JSON Object ("struct") node
*/
@Override
public ObjectNode objectNode() { return new ObjectNode(this); }
/**
* Factory method for constructing a wrapper for POJO
* ("Plain Old Java Object") objects; these will get serialized
* using data binding, usually as JSON Objects, but in some
* cases as JSON Strings or other node types.
*/
@Override
public ValueNode pojoNode(Object pojo) { return new POJONode(pojo); }
@Override
public ValueNode rawValueNode(RawValue value) {
return new POJONode(value);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected boolean _inIntRange(long l)
{
int i = (int) l;
long l2 = (long) i;
return (l2 == l);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>);
}
public SerializerFactoryConfig withSerializerModifier(BeanSerializerModifier modifier)
{
if (modifier == null) {
throw new IllegalArgumentException("Can not pass null modifier");
}
BeanSerializerModifier[] modifiers = ArrayBuilders.insertInListNoDup(_modifiers, modifier);
return new SerializerFactoryConfig(_additionalSerializers, _additionalKeySerializers, modifiers);
}
public boolean hasSerializers() { return _additionalSerializers.length > 0; }
public boolean hasKeySerializers() { return _additionalKeySerializers.length > 0; }
public boolean hasSerializerModifiers() { return _modifiers.length > 0; }
public Iterable<Serializers> serializers() { return new ArrayIterator<Serializers>(_additionalSerializers); }
public Iterable<Serializers> keySerializers() { return new ArrayIterator<Serializers>(_additionalKeySerializers); }
public Iterable<BeanSerializerModifier> serializerModifiers() { return new ArrayIterator<BeanSerializerModifier>(_modifiers); }
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Address.class.isAssignableFrom(raw)) {
return new InetAddressSerializer();
}
if (InetSocketAddress.class.isAssignableFrom(raw)) {
return new InetSocketAddressSerializer();
}
if (TimeZone.class.isAssignableFrom(raw)) {
return new TimeZoneSerializer();
}
if (java.nio.charset.Charset.class.isAssignableFrom(raw)) {
return ToStringSerializer.instance;
}
if (Number.class.isAssignableFrom(raw)) {
// 21-May-2014, tatu: Couple of alternatives actually
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
if (format != null) {
switch (format.getShape()) {
case STRING:
return ToStringSerializer.instance;
case OBJECT: // need to bail out to let it be serialized as POJO
case ARRAY: // or, I guess ARRAY; otherwise no point in speculating
return null;
default:
}
}
return NumberSerializer.instance;
}
if (Enum.class.isAssignableFrom(raw)) {
return buildEnumSerializer(prov.getConfig(), type, beanDesc);
}
return null;
}
/**
* Overridable method called after checking all other types.
*
* @since 2.2
*/
protected JsonSerializer<?> findOptionalStdSerializer(SerializerProvider prov,
JavaType type, BeanDescription beanDesc, boolean staticTyping)
throws JsonMappingException
{
return OptionalHandlerFactory.instance.findSerializer(prov.getConfig(), type, beanDesc);
}
/**
* Reflection-based serialized find method, which checks if
* given class implements one of recognized "add-on" interfaces.
* Add-on here means a role that is usually or can be a secondary
* trait: for example,
* bean classes may implement {@link Iterable}, but their main
* function is usually something else. The reason for
*/
protected final JsonSerializer<?> findSerializerByAddonType(SerializationConfig config,
JavaType javaType, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
{
Class<?> rawType = javaType.getRawClass();
if (Iterator.class.isAssignableFrom(rawType)) {
JavaType[] params = config.getTypeFactory().findTypeParameters(javaType, Iterator.class);
JavaType vt = (params == null || params.length != 1) ?
TypeFactory.unknownType() : params[0];
return buildIteratorSerializer(config, javaType, beanDesc, staticTyping, vt);
}
if (Iterable.class.isAssignableFrom(rawType)) {
Java
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Type[] params = config.getTypeFactory().findTypeParameters(javaType, Iterable.class);
JavaType vt = (params == null || params.length != 1) ?
TypeFactory.unknownType() : params[0];
return buildIterableSerializer(config, javaType, beanDesc, staticTyping, vt);
}
if (CharSequence.class.isAssignableFrom(rawType)) {
return ToStringSerializer.instance;
}
return null;
}
/**
* Helper method called to check if a class or method
* has an annotation
* (@link com.fasterxml.jackson.databind.annotation.JsonSerialize#using)
* that tells the class to use for serialization.
* Returns null if no such annotation found.
*/
@SuppressWarnings("unchecked")
protected JsonSerializer<Object> findSerializerFromAnnotation(SerializerProvider prov,
Annotated a)
throws JsonMappingException
{
Object serDef = prov.getAnnotationIntrospector().findSerializer(a);
if (serDef == null) {
return null;
}
JsonSerializer<Object> ser = prov.serializerInstance(a, serDef);
// One more thing however: may need to also apply a converter:
return (JsonSerializer<Object>) findConvertingSerializer(prov, a, ser);
}
/**
* Helper method that will check whether given annotated entity (usually class,
* but may also be a property accessor) indicates that a {@link Converter} is to
* be used; and if so, to construct and return suitable serializer for it.
* If not, will simply return given serializer as is.
*/
protected JsonSerializer<?> findConvertingSerializer(SerializerProvider prov,
Annotated a, JsonSerializer<?> ser)
throws JsonMappingException
{
Converter<Object,Object> conv = findConverter(prov, a);
if (conv == null) {
return ser;
}
JavaType delegateType = conv.getOutputType(prov.getTypeFactory());
return new StdDelegatingSerializer(conv, delegateType, ser);
}
protected Converter<Object,Object> findConverter(SerializerProvider prov,
Annotated a)
throws JsonMappingException
{
Object convDef = prov.getAnnotationIntrospector().findSerializationConverter(a);
if (convDef == null) {
return null;
}
return prov.converterInstance(a, convDef);
}
/*
/**********************************************************
/* Factory methods, container types:
/**********************************************************
*/
/**
* @since 2.1
*/
protected JsonSerializer<?> buildContainerSerializer(SerializerProvider prov,
JavaType type, BeanDescription bean
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> array serializers
SerializationConfig config = prov.getConfig();
JsonSerializer<?> ser = null;
for (Serializers serializers : customSerializers()) { // (1) Custom
ser = serializers.findArraySerializer(config,
type, beanDesc, elementTypeSerializer, elementValueSerializer);
if (ser != null) {
break;
}
}
if (ser == null) {
Class<?> raw = type.getRawClass();
// Important: do NOT use standard serializers if non-standard element value serializer specified
if (elementValueSerializer == null || ClassUtil.isJacksonStdImpl(elementValueSerializer)) {
if (String[].class == raw) {
ser = StringArraySerializer.instance;
} else {
// other standard types?
ser = StdArraySerializers.findStandardImpl(raw);
}
}
if (ser == null) {
ser = new ObjectArraySerializer(type.getContentType(), staticTyping, elementTypeSerializer,
elementValueSerializer);
}
}
// [databind#120]: Allow post-processing
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
ser = mod.modifyArraySerializer(config, type, beanDesc, ser);
}
}
return ser;
}
/*
/**********************************************************
/* Factory methods, for non-container types
/**********************************************************
*/
/**
* @since 2.5
*/
protected JsonSerializer<?> buildIteratorSerializer(SerializationConfig config,
JavaType type, BeanDescription beanDesc, boolean staticTyping,
JavaType valueType)
throws JsonMappingException
{
return new IteratorSerializer(valueType, staticTyping, createTypeSerializer(config, valueType));
}
@Deprecated // since 2.5
protected JsonSerializer<?> buildIteratorSerializer(SerializationConfig config,
JavaType type, BeanDescription beanDesc, boolean staticTyping) throws JsonMappingException
{
JavaType[] params = config.getTypeFactory().findTypeParameters(type, Iterator.class);
JavaType vt = (params == null || params.length != 1) ?
TypeFactory.unknownType() : params[0];
return buildIteratorSerializer(config, type, beanDesc, staticTyping, vt);
}
/**
* @since 2.5
*/
protected JsonSerializer<?> buildIterableSerializer(SerializationConfig config,
JavaType type, BeanDescription beanDesc, boolean staticTyping,
JavaType valueType)
throws JsonMappingException
{
return new IterableSerializer(valueType, staticTyping, createTypeSerializer(config, valueType));
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> }
@Deprecated // since 2.5
protected JsonSerializer<?> buildIterableSerializer(SerializationConfig config,
JavaType type, BeanDescription beanDesc,
boolean staticTyping)
throws JsonMappingException
{
JavaType[] params = config.getTypeFactory().findTypeParameters(type, Iterable.class);
JavaType vt = (params == null || params.length != 1) ?
TypeFactory.unknownType() : params[0];
return buildIterableSerializer(config, type, beanDesc, staticTyping, vt);
}
/**
* @since 2.5
*/
protected JsonSerializer<?> buildMapEntrySerializer(SerializationConfig config,
JavaType type, BeanDescription beanDesc, boolean staticTyping,
JavaType keyType, JavaType valueType)
throws JsonMappingException
{
return new MapEntrySerializer(valueType, keyType, valueType,
staticTyping, createTypeSerializer(config, valueType), null);
}
protected JsonSerializer<?> buildEnumSerializer(SerializationConfig config,
JavaType type, BeanDescription beanDesc)
throws JsonMappingException
{
/* As per [databind#24], may want to use alternate shape, serialize as JSON Object.
* Challenge here is that EnumSerializer does not know how to produce
* POJO style serialization, so we must handle that special case separately;
* otherwise pass it to EnumSerializer.
*/
JsonFormat.Value format = beanDesc.findExpectedFormat(null);
if (format != null && format.getShape() == JsonFormat.Shape.OBJECT) {
// one special case: suppress serialization of "getDeclaringClass()"...
((BasicBeanDescription) beanDesc).removeProperty("declaringClass");
// returning null will mean that eventually BeanSerializer gets constructed
return null;
}
@SuppressWarnings("unchecked")
Class<Enum<?>> enumClass = (Class<Enum<?>>) type.getRawClass();
JsonSerializer<?> ser = EnumSerializer.construct(enumClass, config, beanDesc, format);
// [Issue#120]: Allow post-processing
if (_factoryConfig.hasSerializerModifiers()) {
for (BeanSerializerModifier mod : _factoryConfig.serializerModifiers()) {
ser = mod.modifyEnumSerializer(config, type, beanDesc, ser);
}
}
return ser;
}
/*
/**********************************************************
/* Other helper methods
/**********************************************************
*/
/**
* Helper method called to try to find whether there is an annotation in the
* class that indicates key serializer to use.
* If so, will try to instantiate key serializer and return it; otherwise returns null.
*/
protected JsonSerializer
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import java.io.IOException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
/**
* Simple serializer for {@link InetSocketAddress}.
*/
@SuppressWarnings("serial")
public class InetSocketAddressSerializer
extends StdScalarSerializer<InetSocketAddress>
{
public InetSocketAddressSerializer() { super(InetSocketAddress.class); }
@Override
public void serialize(InetSocketAddress value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
InetAddress addr = value.getAddress();
String str = addr == null ? value.getHostName() : addr.toString().trim();
int ix = str.indexOf('/');
if (ix >= 0) {
if (ix == 0) { // missing host name; use address
str = addr instanceof Inet6Address
? "[" + str.substring(1) + "]" // bracket IPv6 addresses with
: str.substring(1);
} else { // otherwise use name
str = str.substring(0, ix);
}
}
jgen.writeString(str + ":" + value.getPort());
}
@Override
public void serializeWithType(InetSocketAddress value, JsonGenerator jgen, SerializerProvider provider, TypeSerializer typeSer) throws IOException, JsonGenerationException
{
// Better ensure we don't use specific sub-classes...
typeSer.writeTypePrefixForScalar(value, jgen, InetSocketAddress.class);
serialize(value, jgen, provider);
typeSer.writeTypeSuffixForScalar(value, jgen);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> _filterProvider;
/**
* If "default pretty-printing" is enabled, it will create the instance
* from this blueprint object.
*
* @since 2.6
*/
protected final PrettyPrinter _defaultPrettyPrinter;
/*
/**********************************************************
/* Serialization features
/**********************************************************
*/
/**
* Set of {@link SerializationFeature}s enabled.
*/
protected final int _serFeatures;
/*
/**********************************************************
/* Generator features: generic, format-specific
/**********************************************************
*/
/**
* States of {@link com.fasterxml.jackson.core.JsonGenerator.Feature}s to enable/disable.
*/
protected final int _generatorFeatures;
/**
* Bitflag of {@link com.fasterxml.jackson.core.JsonGenerator.Feature}s to enable/disable
*/
protected final int _generatorFeaturesToChange;
/**
* States of {@link com.fasterxml.jackson.core.FormatFeature}s to enable/disable.
*
* @since 2.7
*/
protected final int _formatWriteFeatures;
/**
* Bitflag of {@link com.fasterxml.jackson.core.FormatFeature}s to enable/disable
*
* @since 2.7
*/
protected final int _formatWriteFeaturesToChange;
/*
/**********************************************************
/* Other configuration
/**********************************************************
*/
/**
* Which Bean/Map properties are to be included in serialization?
* Default settings is to include all regardless of value; can be
* changed to only include non-null properties, or properties
* with non-default values.
*<p>
* NOTE: type changed in 2.7, to include both value and content
* inclusion options./
*/
protected final JsonInclude.Value _serializationInclusion;
/*
/**********************************************************
/* Life-cycle, constructors
/**********************************************************
*/
/**
* Constructor used by ObjectMapper to create default configuration object instance.
*/
public SerializationConfig(BaseSettings base,
SubtypeResolver str, SimpleMixInResolver mixins,
RootNameLookup rootNames)
{
super(base, str, mixins, rootNames);
_serFeatures = collectFeatureDefaults(SerializationFeature.class);
_filterProvider = null;
_defaultPrettyPrinter = DEFAULT_PRETTY_PRINTER;
_generatorFeatures = 0;
_generatorFeaturesToChange = 0;
_formatWriteFeatures = 0;
_formatWriteFeaturesToChange = 0;
_serializationInclusion = DEFAULT_INCLUSION;
}
private SerializationConfig(SerializationConfig src,
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> SubtypeResolver str)
{
super(src, str);
_serFeatures = src._serFeatures;
_serializationInclusion = src._serializationInclusion;
_filterProvider = src._filterProvider;
_defaultPrettyPrinter = src._defaultPrettyPrinter;
_generatorFeatures = src._generatorFeatures;
_generatorFeaturesToChange = src._generatorFeaturesToChange;
_formatWriteFeatures = src._formatWriteFeatures;
_formatWriteFeaturesToChange = src._formatWriteFeaturesToChange;
}
private SerializationConfig(SerializationConfig src,
int mapperFeatures, int serFeatures,
int generatorFeatures, int generatorFeatureMask,
int formatFeatures, int formatFeaturesMask)
{
super(src, mapperFeatures);
_serFeatures = serFeatures;
_serializationInclusion = src._serializationInclusion;
_filterProvider = src._filterProvider;
_defaultPrettyPrinter = src._defaultPrettyPrinter;
_generatorFeatures = generatorFeatures;
_generatorFeaturesToChange = generatorFeatureMask;
_formatWriteFeatures = formatFeatures;
_formatWriteFeaturesToChange = formatFeaturesMask;
}
private SerializationConfig(SerializationConfig src, BaseSettings base)
{
super(src, base);
_serFeatures = src._serFeatures;
_serializationInclusion = src._serializationInclusion;
_filterProvider = src._filterProvider;
_defaultPrettyPrinter = src._defaultPrettyPrinter;
_generatorFeatures = src._generatorFeatures;
_generatorFeaturesToChange = src._generatorFeaturesToChange;
_formatWriteFeatures = src._formatWriteFeatures;
_formatWriteFeaturesToChange = src._formatWriteFeaturesToChange;
}
private SerializationConfig(SerializationConfig src, FilterProvider filters)
{
super(src);
_serFeatures = src._serFeatures;
_serializationInclusion = src._serializationInclusion;
_filterProvider = filters;
_defaultPrettyPrinter = src._defaultPrettyPrinter;
_generatorFeatures = src._generatorFeatures;
_generatorFeaturesToChange = src._generatorFeaturesToChange;
_formatWriteFeatures = src._formatWriteFeatures;
_formatWriteFeaturesToChange = src._formatWriteFeaturesToChange;
}
private SerializationConfig(SerializationConfig src, Class<?> view)
{
super(src, view);
_serFeatures = src._serFeatures;
_serializationInclusion = src._serializationInclusion;
_filterProvider = src._filterProvider;
_defaultPrettyPrinter = src._defaultPrettyPrinter;
_generatorFeatures = src._generatorFeatures;
_generatorFeaturesToChange = src._generatorFeaturesToChange;
_formatWriteFeatures =
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
newMapperFlags = _mapperFeatures | feature.getMask();
} else {
newMapperFlags = _mapperFeatures & ~feature.getMask();
}
return (newMapperFlags == _mapperFeatures) ? this
: new SerializationConfig(this, newMapperFlags, _serFeatures,
_generatorFeatures, _generatorFeaturesToChange,
_formatWriteFeatures, _formatWriteFeaturesToChange);
}
@Override
public SerializationConfig with(AnnotationIntrospector ai) {
return _withBase(_base.withAnnotationIntrospector(ai));
}
@Override
public SerializationConfig withAppendedAnnotationIntrospector(AnnotationIntrospector ai) {
return _withBase(_base.withAppendedAnnotationIntrospector(ai));
}
@Override
public SerializationConfig withInsertedAnnotationIntrospector(AnnotationIntrospector ai) {
return _withBase(_base.withInsertedAnnotationIntrospector(ai));
}
@Override
public SerializationConfig with(ClassIntrospector ci) {
return _withBase(_base.withClassIntrospector(ci));
}
/**
* In addition to constructing instance with specified date format,
* will enable or disable <code>SerializationFeature.WRITE_DATES_AS_TIMESTAMPS</code>
* (enable if format set as null; disable if non-null)
*/
@Override
public SerializationConfig with(DateFormat df) {
SerializationConfig cfg = new SerializationConfig(this, _base.withDateFormat(df));
// Also need to toggle this feature based on existence of date format:
if (df == null) {
cfg = cfg.with(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
} else {
cfg = cfg.without(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
}
return cfg;
}
@Override
public SerializationConfig with(HandlerInstantiator hi) {
return _withBase(_base.withHandlerInstantiator(hi));
}
@Override
public SerializationConfig with(PropertyNamingStrategy pns) {
return _withBase(_base.withPropertyNamingStrategy(pns));
}
@Override
public SerializationConfig withRootName(PropertyName rootName) {
if (rootName == null) {
if (_rootName == null) {
return this;
}
} else if (rootName.equals(_rootName)) {
return this;
}
return new SerializationConfig(this, rootName);
}
@Override
public SerializationConfig with(SubtypeResolver str) {
return (str == _subtypeResolver
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>)? this : new SerializationConfig(this, str);
}
@Override
public SerializationConfig with(TypeFactory tf) {
return _withBase(_base.withTypeFactory(tf));
}
@Override
public SerializationConfig with(TypeResolverBuilder<?> trb) {
return _withBase(_base.withTypeResolverBuilder(trb));
}
@Override
public SerializationConfig withView(Class<?> view) {
return (_view == view) ? this : new SerializationConfig(this, view);
}
@Override
public SerializationConfig with(VisibilityChecker<?> vc) {
return _withBase(_base.withVisibilityChecker(vc));
}
@Override
public SerializationConfig withVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility) {
return _withBase(_base.withVisibility(forMethod, visibility));
}
@Override
public SerializationConfig with(Locale l) {
return _withBase(_base.with(l));
}
@Override
public SerializationConfig with(TimeZone tz) {
return _withBase(_base.with(tz));
}
@Override
public SerializationConfig with(Base64Variant base64) {
return _withBase(_base.with(base64));
}
@Override
public SerializationConfig with(ContextAttributes attrs) {
return (attrs == _attributes) ? this : new SerializationConfig(this, attrs);
}
private final SerializationConfig _withBase(BaseSettings newBase) {
return (_base == newBase) ? this : new SerializationConfig(this, newBase);
}
/*
/**********************************************************
/* Factory methods for SerializationFeature
/**********************************************************
*/
/**
* Fluent factory method that will construct and return a new configuration
* object instance with specified feature enabled.
*/
public SerializationConfig with(SerializationFeature feature)
{
int newSerFeatures = _serFeatures | feature.getMask();
return (newSerFeatures == _serFeatures) ? this
: new SerializationConfig(this, _mapperFeatures, newSerFeatures,
_generatorFeatures, _generatorFeaturesToChange,
_formatWriteFeatures, _formatWriteFeaturesToChange);
}
/**
* Fluent factory method that will construct and return a new configuration
* object instance with specified features enabled.
*/
public SerializationConfig with(SerializationFeature first, SerializationFeature... features)
{
int newSerFeatures = _serFeatures | first.getMask();
for (SerializationFeature f : features) {
newSerFeatures |= f.getMask();
}
return (newSerFeatures == _serFeatures) ? this
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>ified" simple time stamp
int i = dateStr.length();
while (--i >= 0) {
char ch = dateStr.charAt(i);
if (ch < '0' || ch > '9') {
// 07-Aug-2013, tatu: And [databind#267] points out that negative numbers should also work
if (i > 0 || ch != '-') {
break;
}
}
}
if ((i < 0)
// let's just assume negative numbers are fine (can't be RFC-1123 anyway); check length for positive
&& (dateStr.charAt(0) == '-' || NumberInput.inLongRange(dateStr, false))) {
dt = new Date(Long.parseLong(dateStr));
} else {
// Otherwise, fall back to using RFC 1123
dt = parseAsRFC1123(dateStr, pos);
}
}
if (dt != null) {
return dt;
}
StringBuilder sb = new StringBuilder();
for (String f : ALL_FORMATS) {
if (sb.length() > 0) {
sb.append("\", \"");
} else {
sb.append('"');
}
sb.append(f);
}
sb.append('"');
throw new ParseException
(String.format("Can not parse date \"%s\": not compatible with any of standard forms (%s)",
dateStr, sb.toString()), pos.getErrorIndex());
}
@Override
public Date parse(String dateStr, ParsePosition pos)
{
if (looksLikeISO8601(dateStr)) { // also includes "plain"
try {
return parseAsISO8601(dateStr, pos, false);
} catch (ParseException e) { // will NOT be thrown due to false but is declared...
return null;
}
}
// Also consider "stringified" simple time stamp
int i = dateStr.length();
while (--i >= 0) {
char ch = dateStr.charAt(i);
if (ch < '0' || ch > '9') {
// 07-Aug-2013, tatu: And [databind#267] points out that negative numbers should also work
if (i > 0 || ch != '-') {
break;
}
}
}
if (i < 0) { // all digits
// let's just assume negative numbers are fine (can't be RFC-1123 anyway
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>); check length for positive
if (dateStr.charAt(0) == '-' || NumberInput.inLongRange(dateStr, false)) {
return new Date(Long.parseLong(dateStr));
}
}
// Otherwise, fall back to using RFC 1123
return parseAsRFC1123(dateStr, pos);
}
/*
/**********************************************************
/* Public API, writing
/**********************************************************
*/
@Override
public StringBuffer format(Date date, StringBuffer toAppendTo,
FieldPosition fieldPosition)
{
if (_formatISO8601 == null) {
_formatISO8601 = _cloneFormat(DATE_FORMAT_ISO8601, DATE_FORMAT_STR_ISO8601,
_timezone, _locale, _lenient);
}
return _formatISO8601.format(date, toAppendTo, fieldPosition);
}
/*
/**********************************************************
/* Std overrides
/**********************************************************
*/
@Override
public String toString() {
String str = "DateFormat "+getClass().getName();
TimeZone tz = _timezone;
if (tz != null) {
str += " (timezone: "+tz+")";
}
str += "(locale: "+_locale+")";
return str;
}
@Override // since 2.7[.2], as per [databind#1130]
public boolean equals(Object o) {
return (o == this);
}
@Override // since 2.7[.2], as per [databind#1130]
public int hashCode() {
return System.identityHashCode(this);
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
/**
* Overridable helper method used to figure out which of supported
* formats is the likeliest match.
*/
protected boolean looksLikeISO8601(String dateStr)
{
if (dateStr.length() >= 5
&& Character.isDigit(dateStr.charAt(0))
&& Character.isDigit(dateStr.charAt(3))
&& dateStr.charAt(4) == '-'
) {
return true;
}
return false;
}
protected Date parseAsISO8601(String dateStr, ParsePosition pos, boolean throwErrors)
throws ParseException
{
/* 21-May-2009, tatu: DateFormat has very strict handling of
* timezone modifiers for ISO-8601. So we need to do some scr
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>ubbing.
*/
/* First: do we have "zulu" format ('Z' == "UTC")? If yes, that's
* quite simple because we already set date format timezone to be
* UTC, and hence can just strip out 'Z' altogether
*/
int len = dateStr.length();
char c = dateStr.charAt(len-1);
DateFormat df;
String formatStr;
// Need to support "plain" date...
if (len <= 10 && Character.isDigit(c)) {
df = _formatPlain;
formatStr = DATE_FORMAT_STR_PLAIN;
if (df == null) {
df = _formatPlain = _cloneFormat(DATE_FORMAT_PLAIN, formatStr,
_timezone, _locale, _lenient);
}
} else if (c == 'Z') {
df = _formatISO8601_z;
formatStr = DATE_FORMAT_STR_ISO8601_Z;
if (df == null) {
df = _formatISO8601_z = _cloneFormat(DATE_FORMAT_ISO8601_Z, formatStr,
_timezone, _locale, _lenient);
}
// may be missing milliseconds... if so, add
if (dateStr.charAt(len-4) == ':') {
StringBuilder sb = new StringBuilder(dateStr);
sb.insert(len-1, ".000");
dateStr = sb.toString();
}
} else {
// Let's see if we have timezone indicator or not...
if (hasTimeZone(dateStr)) {
c = dateStr.charAt(len-3);
if (c == ':') { // remove optional colon
// remove colon
StringBuilder sb = new StringBuilder(dateStr);
sb.delete(len-3, len-2);
dateStr = sb.toString();
} else if (c == '+' || c == '-') { // missing minutes
// let's just append '00'
dateStr += "00";
}
// Milliseconds partial or missing; and even seconds are optional
len = dateStr.length();
// remove 'T', '+'/'-' and 4-digit timezone-offset
int timeLen = len - dateStr.lastIndexOf('T') - 6;
if (timeLen < 12) { // 8 for hh:mm:ss, 4 for .sss
int offset = len - 5; // insertion offset, before tz-offset
StringBuilder sb = new StringBuilder(dateStr
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> while it seems to fit format '%s', parsing fails (leniency? %s)",
dateStr, formatStr, _lenient),
pos.getErrorIndex());
}
return dt;
}
protected Date parseAsRFC1123(String dateStr, ParsePosition pos)
{
if (_formatRFC1123 == null) {
_formatRFC1123 = _cloneFormat(DATE_FORMAT_RFC1123, DATE_FORMAT_STR_RFC1123,
_timezone, _locale, _lenient);
}
return _formatRFC1123.parse(dateStr, pos);
}
private final static boolean hasTimeZone(String str)
{
// Only accept "+hh", "+hhmm" and "+hh:mm" (and with minus), so
int len = str.length();
if (len >= 6) {
char c = str.charAt(len-6);
if (c == '+' || c == '-') return true;
c = str.charAt(len-5);
if (c == '+' || c == '-') return true;
c = str.charAt(len-3);
if (c == '+' || c == '-') return true;
}
return false;
}
private final static DateFormat _cloneFormat(DateFormat df, String format,
TimeZone tz, Locale loc, Boolean lenient)
{
if (!loc.equals(DEFAULT_LOCALE)) {
df = new SimpleDateFormat(format, loc);
df.setTimeZone((tz == null) ? DEFAULT_TIMEZONE : tz);
} else {
df = (DateFormat) df.clone();
if (tz != null) {
df.setTimeZone(tz);
}
}
if (lenient != null) {
df.setLenient(lenient.booleanValue());
}
return df;
}
protected void _clearFormats() {
_formatRFC1123 = null;
_formatISO8601 = null;
_formatISO8601_z = null;
_formatPlain = null;
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> == null) {
return NO_NAME;
}
return this;
}
/**
* @since 2.6
*/
public static PropertyName construct(String simpleName)
{
if (simpleName == null || simpleName.length() == 0) {
return USE_DEFAULT;
}
return new PropertyName(InternCache.instance.intern(simpleName), null);
}
public static PropertyName construct(String simpleName, String ns)
{
if (simpleName == null) {
simpleName = "";
}
if (ns == null && simpleName.length() == 0) {
return USE_DEFAULT;
}
return new PropertyName(InternCache.instance.intern(simpleName), ns);
}
public PropertyName internSimpleName()
{
if (_simpleName.length() == 0) { // empty String is canonical already
return this;
}
String interned = InternCache.instance.intern(_simpleName);
if (interned == _simpleName) { // was already interned
return this;
}
return new PropertyName(interned, _namespace);
}
/**
* Fluent factory method for constructing an instance with different
* simple name.
*/
public PropertyName withSimpleName(String simpleName)
{
if (simpleName == null) {
simpleName = "";
}
if (simpleName.equals(_simpleName)) {
return this;
}
return new PropertyName(simpleName, _namespace);
}
/**
* Fluent factory method for constructing an instance with different
* namespace.
*/
public PropertyName withNamespace(String ns) {
if (ns == null) {
if (_namespace == null) {
return this;
}
} else if (ns.equals(_namespace)) {
return this;
}
return new PropertyName(_simpleName, ns);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
public String getSimpleName() {
return _simpleName;
}
/**
* Accessor that may be used to get lazily-constructed efficient
* representation of the simple name.
*
* @since 2.4
*/
public SerializableString simpleAsEncoded(MapperConfig<?> config) {
SerializableString sstr = _encodedSimple;
if (sstr == null) {
if (config == null) {
sstr = new SerializedString(_simpleName);
} else {
sstr = config.compileString(_simpleName);
}
_encodedSimple = sstr
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>;
}
return sstr;
}
public String getNamespace() {
return _namespace;
}
public boolean hasSimpleName() {
return _simpleName.length() > 0;
}
/**
* @since 2.3
*/
public boolean hasSimpleName(String str) {
if (str == null) {
return _simpleName == null;
}
return str.equals(_simpleName);
}
public boolean hasNamespace() {
return _namespace != null;
}
/**
* Method that is basically equivalent of:
*<pre>
* !hasSimpleName() << !hasNamespace();
*</pre>
*
* @since 2.4
*/
public boolean isEmpty() {
return (_namespace == null) && (_simpleName.isEmpty());
}
/*
/**********************************************************
/* Std method overrides
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
/* 13-Nov-2012, tatu: by default, require strict type equality.
* Re-evaluate if this becomes an issue.
*/
if (o.getClass() != getClass()) return false;
// 13-Nov-2012, tatu: Should we have specific rules on matching USE_DEFAULT?
// (like, it only ever matching exact instance)
// If we did, would need to check symmetrically; that is, if either 'this'
// or 'o' was USE_DEFAULT, both would have to be.
PropertyName other = (PropertyName) o;
if (_simpleName == null) {
if (other._simpleName != null) return false;
} else if (!_simpleName.equals(other._simpleName)) {
return false;
}
if (_namespace == null) {
return (null == other._namespace);
}
return _namespace.equals(other._namespace);
}
@Override
public int hashCode() {
if (_namespace == null) {
return _simpleName.hashCode();
}
return _namespace.hashCode() ^ _simpleName.hashCode();
}
@Override
public String toString() {
if (_namespace == null) {
return _simpleName;
}
return "{"+_namespace + "}" + _simpleName;
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.util.Arrays;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Value node that contains Base64 encoded binary value, which will be
* output and stored as Json String value.
*/
public class BinaryNode
extends ValueNode
{
final static BinaryNode EMPTY_BINARY_NODE = new BinaryNode(new byte[0]);
protected final byte[] _data;
public BinaryNode(byte[] data)
{
_data = data;
}
public BinaryNode(byte[] data, int offset, int length)
{
if (offset == 0 && length == data.length) {
_data = data;
} else {
_data = new byte[length];
System.arraycopy(data, offset, _data, 0, length);
}
}
public static BinaryNode valueOf(byte[] data)
{
if (data == null) {
return null;
}
if (data.length == 0) {
return EMPTY_BINARY_NODE;
}
return new BinaryNode(data);
}
public static BinaryNode valueOf(byte[] data, int offset, int length)
{
if (data == null) {
return null;
}
if (length == 0) {
return EMPTY_BINARY_NODE;
}
return new BinaryNode(data, offset, length);
}
@Override
public JsonNodeType getNodeType()
{
return JsonNodeType.BINARY;
}
@Override
public JsonToken asToken() {
/* No distinct type; could use one for textual values,
* but given that it's not in text form at this point,
* embedded-object is closest
*/
return JsonToken.VALUE_EMBEDDED_OBJECT;
}
/**
*<p>
* Note: caller is not to modify returned array in any way, since
* it is not a copy but reference to the underlying byte array.
*/
@Override
public byte[] binaryValue() { return _data; }
/**
* Hmmh. This is not quite as efficient as using {@link #serialize},
* but will work correctly.
*/
@Override
public String asText() {
return Base64Variants.getDefaultVariant().encode(_data, false);
}
@Override
public final void serialize(JsonGenerator jg, SerializerProvider provider)
throws IOException, JsonProcessingException
{
jg.
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>writeBinary(provider.getConfig().getBase64Variant(),
_data, 0, _data.length);
}
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (!(o instanceof BinaryNode)) {
return false;
}
return Arrays.equals(((BinaryNode) o)._data, _data);
}
@Override
public int hashCode() {
return (_data == null) ? -1 : _data.length;
}
/**
* Different from other values, since contents need to be surrounded
* by (double) quotes.
*/
@Override
public String toString()
{
return Base64Variants.getDefaultVariant().encode(_data, true);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Serializer _withValueTypeSerializer(TypeSerializer vts) {
if (_valueTypeSerializer == vts) {
return this;
}
_ensureOverride();
return new MapSerializer(this, vts, null);
}
/**
* @since 2.4
*/
public MapSerializer withResolved(BeanProperty property,
JsonSerializer<?> keySerializer, JsonSerializer<?> valueSerializer,
HashSet<String> ignored, boolean sortKeys)
{
_ensureOverride();
MapSerializer ser = new MapSerializer(this, property, keySerializer, valueSerializer, ignored);
if (sortKeys != ser._sortKeys) {
ser = new MapSerializer(ser, _filterId, sortKeys);
}
return ser;
}
@Override
public MapSerializer withFilterId(Object filterId) {
if (_filterId == filterId) {
return this;
}
_ensureOverride();
return new MapSerializer(this, filterId, _sortKeys);
}
/**
* Mutant factory for constructing an instance with different inclusion strategy
* for content (Map values).
*
* @since 2.5
*/
public MapSerializer withContentInclusion(Object suppressableValue) {
if (suppressableValue == _suppressableValue) {
return this;
}
_ensureOverride();
return new MapSerializer(this, _valueTypeSerializer, suppressableValue);
}
/**
* @since 2.3
*/
public static MapSerializer construct(String[] ignoredList, JavaType mapType,
boolean staticValueType, TypeSerializer vts,
JsonSerializer<Object> keySerializer, JsonSerializer<Object> valueSerializer,
Object filterId)
{
HashSet<String> ignoredEntries = (ignoredList == null || ignoredList.length == 0)
? null : ArrayBuilders.arrayToSet(ignoredList);
JavaType keyType, valueType;
if (mapType == null) {
keyType = valueType = UNSPECIFIED_TYPE;
} else {
keyType = mapType.getKeyType();
valueType = mapType.getContentType();
}
// If value type is final, it's same as forcing static value typing:
if (!staticValueType) {
staticValueType = (valueType != null && valueType.isFinal());
} else {
// also: Object.class can not be handled as static, ever
if (valueType.getRawClass() == Object.class) {
staticValueType = false;
}
}
MapSerializer ser = new MapSerializer(ignoredEntries, keyType, valueType, staticValueType, vts,
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> (keySer == null) {
keySer = _keySerializer;
}
if (keySer == null) {
keySer = provider.findKeySerializer(_keyType, property);
} else {
keySer = provider.handleSecondaryContextualization(keySer, property);
}
HashSet<String> ignored = _ignoredEntries;
boolean sortKeys = false;
if (intr != null && propertyAcc != null) {
String[] moreToIgnore = intr.findPropertiesToIgnore(propertyAcc, true);
if (moreToIgnore != null) {
ignored = (ignored == null) ? new HashSet<String>() : new HashSet<String>(ignored);
for (String str : moreToIgnore) {
ignored.add(str);
}
}
Boolean b = intr.findSerializationSortAlphabetically(propertyAcc);
sortKeys = (b != null) && b.booleanValue();
}
MapSerializer mser = withResolved(property, keySer, ser, ignored, sortKeys);
if (suppressableValue != _suppressableValue) {
mser = mser.withContentInclusion(suppressableValue);
}
// [databind#307]: allow filtering
if (property != null) {
AnnotatedMember m = property.getMember();
if (m != null) {
Object filterId = intr.findFilterId(m);
if (filterId != null) {
mser = mser.withFilterId(filterId);
}
}
}
return mser;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _valueType;
}
@Override
public JsonSerializer<?> getContentSerializer() {
return _valueSerializer;
}
@Override
public boolean isEmpty(SerializerProvider prov, Map<?,?> value)
{
if (value == null || value.isEmpty()) {
return true;
}
// 05-Nove-2015, tatu: Simple cases are cheap, but for recursive
// emptiness checking we actually need to see if values are empty as well.
Object supp = this._suppressableValue;
if ((supp == null) || (supp == JsonInclude.Include.ALWAYS)) {
return false;
}
JsonSerializer<Object> valueSer = _valueSerializer;
if (valueSer != null) {
for (Object elemValue : value.values()) {
if ((elemValue != null) && !valueSer.isEmpty(prov, elemValue)) {
return
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>BooleanFromOther(jp, ctxt);
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
// [#422]: Allow aliases
if ("true".equals(text) || "True".equals(text)) {
return true;
}
if ("false".equals(text) || "False".equals(text) || text.length() == 0) {
return false;
}
if (_hasTextualNull(text)) {
return false;
}
throw ctxt.weirdStringException(text, _valueClass, "only \"true\" or \"false\" recognized");
}
// [databind#381]
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final boolean parsed = _parseBooleanPrimitive(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'boolean' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final Boolean _parseBoolean(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_TRUE) {
return Boolean.TRUE;
}
if (t == JsonToken.VALUE_FALSE) {
return Boolean.FALSE;
}
// [JACKSON-78]: should accept ints too, (0 == false, otherwise true)
if (t == JsonToken.VALUE_NUMBER_INT) {
// 11-Jan-2012, tatus: May be outside of int...
if (p.getNumberType() == NumberType.INT) {
return (p.getIntValue() == 0) ? Boolean.FALSE : Boolean.TRUE;
}
return Boolean.valueOf(_parseBooleanFromOther(p, ctxt));
}
if (t == JsonToken.VALUE_NULL) {
return (Boolean) getNullValue(ctxt);
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = p.getText().trim();
// [#42
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>2]: Allow aliases
if ("true".equals(text) || "True".equals(text)) {
return Boolean.TRUE;
}
if ("false".equals(text) || "False".equals(text)) {
return Boolean.FALSE;
}
if (text.length() == 0) {
return (Boolean) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Boolean) getNullValue(ctxt);
}
throw ctxt.weirdStringException(text, _valueClass, "only \"true\" or \"false\" recognized");
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Boolean parsed = _parseBoolean(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Boolean' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final boolean _parseBooleanFromOther(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (p.getNumberType() == NumberType.LONG) {
return (p.getLongValue() == 0L) ? Boolean.FALSE : Boolean.TRUE;
}
// no really good logic; let's actually resort to textual comparison
String str = p.getText();
if ("0.0".equals(str) || "0".equals(str)) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
protected Byte _parseByte(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return p.getByteValue();
}
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
if (_hasTextualNull(text)) {
return (Byte) getNullValue(ctxt);
}
int value;
try {
int len = text.length();
if (len == 0) {
return (Byte) getEmptyValue(ctxt);
}
value = NumberInput.parseInt(text);
} catch (
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid Byte value");
}
// So far so good: but does it fit?
// as per [JACKSON-804], allow range up to 255, inclusive
if (value < Byte.MIN_VALUE || value > 255) {
throw ctxt.weirdStringException(text, _valueClass, "overflow, value can not be represented as 8-bit value");
}
return Byte.valueOf((byte) value);
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Byte");
}
return p.getByteValue();
}
if (t == JsonToken.VALUE_NULL) {
return (Byte) getNullValue(ctxt);
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Byte parsed = _parseByte(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Byte' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_valueClass, t);
}
protected Short _parseShort(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return p.getShortValue();
}
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
int value;
try {
int len = text.length();
if (len == 0) {
return (Short) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Short) getNullValue(ctxt);
}
value = NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid Short value");
}
// So far so good: but does it fit?
if (value < Short.MIN
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>_VALUE || value > Short.MAX_VALUE) {
throw ctxt.weirdStringException(text, _valueClass, "overflow, value can not be represented as 16-bit value");
}
return Short.valueOf((short) value);
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Short");
}
return p.getShortValue();
}
if (t == JsonToken.VALUE_NULL) {
return (Short) getNullValue(ctxt);
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Short parsed = _parseShort(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Short' value but there was more than a single value in the array");
}
return parsed;
}
throw ctxt.mappingException(_valueClass, t);
}
protected final short _parseShortPrimitive(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
int value = _parseIntPrimitive(jp, ctxt);
// So far so good: but does it fit?
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw ctxt.weirdStringException(String.valueOf(value),
_valueClass, "overflow, value can not be represented as 16-bit value");
}
return (short) value;
}
protected final int _parseIntPrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (p.hasToken(JsonToken.VALUE_NUMBER_INT)) {
return p.getIntValue();
}
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING) { // let's do implicit re-parse
String text = p.getText().trim();
if (_hasTextualNull(text)) {
return 0;
}
try {
int len = text.length();
if (len > 9) {
long l = Long.parseLong(text);
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
throw ctxt.weird
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>StringException(text, _valueClass,
"Overflow: numeric value ("+text+") out of range of int ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")");
}
return (int) l;
}
if (len == 0) {
return 0;
}
return NumberInput.parseInt(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid int value");
}
}
if (t == JsonToken.VALUE_NUMBER_FLOAT) {
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "int");
}
return p.getValueAsInt();
}
if (t == JsonToken.VALUE_NULL) {
return 0;
}
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final int parsed = _parseIntPrimitive(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'int' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final Integer _parseInteger(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
// NOTE: caller assumed to usually check VALUE_NUMBER_INT in fast path
case JsonTokenId.ID_NUMBER_INT:
return Integer.valueOf(p.getIntValue());
case JsonTokenId.ID_NUMBER_FLOAT: // coercing may work too
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Integer");
}
return Integer.valueOf(p.getValueAsInt());
case JsonTokenId.ID_STRING: // let's do implicit re-parse
String text = p.getText().trim();
try {
int len = text.length();
if (_hasTextualNull(text)) {
return (Integer) getNullValue(ctxt);
}
if (len > 9) {
long l = Long.parseLong(text);
if (l < Integer
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>.MIN_VALUE || l > Integer.MAX_VALUE) {
throw ctxt.weirdStringException(text, _valueClass,
"Overflow: numeric value ("+text+") out of range of Integer ("+Integer.MIN_VALUE+" - "+Integer.MAX_VALUE+")");
}
return Integer.valueOf((int) l);
}
if (len == 0) {
return (Integer) getEmptyValue(ctxt);
}
return Integer.valueOf(NumberInput.parseInt(text));
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid Integer value");
}
case JsonTokenId.ID_NULL:
return (Integer) getNullValue(ctxt);
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Integer parsed = _parseInteger(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Integer' value but there was more than a single value in the array");
}
return parsed;
}
break;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
protected final Long _parseLong(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
// NOTE: caller assumed to usually check VALUE_NUMBER_INT in fast path
case JsonTokenId.ID_NUMBER_INT:
return p.getLongValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "Long");
}
return p.getValueAsLong();
case JsonTokenId.ID_STRING:
// let's allow Strings to be converted too
// !!! 05-Jan-2009, tatu: Should we try to limit value space, JDK is too lenient?
String text = p.getText().trim();
if (text.length() == 0) {
return (Long) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Long) getNullValue(ctxt);
}
try {
return Long.valueOf(NumberInput.parseLong(text));
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid Long value");
case JsonTokenId.ID_NULL:
return (Long) getNullValue(ctxt);
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Long parsed = _parseLong(p, ctxt);
JsonToken t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Long' value but there was more than a single value in the array");
}
return parsed;
}
break;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
protected final long _parseLongPrimitive(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
return p.getLongValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "long");
}
return p.getValueAsLong();
case JsonTokenId.ID_STRING:
String text = p.getText().trim();
if (text.length() == 0 || _hasTextualNull(text)) {
return 0L;
}
try {
return NumberInput.parseLong(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid long value");
case JsonTokenId.ID_NULL:
return 0L;
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final long parsed = _parseLongPrimitive(p, ctxt);
JsonToken t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'long' value but there was more than a single value in the array");
}
return parsed;
}
break;
}
throw ctxt.mappingException(_valueClass,
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> p.getCurrentToken());
}
protected final Float _parseFloat(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
// We accept couple of different types; obvious ones first:
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
return jp.getFloatValue();
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if (text.length() == 0) {
return (Float) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Float) getNullValue(ctxt);
}
switch (text.charAt(0)) {
case 'I':
if (_isPosInf(text)) {
return Float.POSITIVE_INFINITY;
}
break;
case 'N':
if (_isNaN(text)) {
return Float.NaN;
}
break;
case '-':
if (_isNegInf(text)) {
return Float.NEGATIVE_INFINITY;
}
break;
}
try {
return Float.parseFloat(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid Float value");
}
if (t == JsonToken.VALUE_NULL) {
return (Float) getNullValue(ctxt);
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final Float parsed = _parseFloat(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Byte' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final float _parseFloatPrimitive(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
return jp.getFloatValue();
}
if
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if (text.length() == 0 || _hasTextualNull(text)) {
return 0.0f;
}
switch (text.charAt(0)) {
case 'I':
if (_isPosInf(text)) {
return Float.POSITIVE_INFINITY;
}
break;
case 'N':
if (_isNaN(text)) { return Float.NaN; }
break;
case '-':
if (_isNegInf(text)) {
return Float.NEGATIVE_INFINITY;
}
break;
}
try {
return Float.parseFloat(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid float value");
}
if (t == JsonToken.VALUE_NULL) {
return 0.0f;
}
// Issue#381
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final float parsed = _parseFloatPrimitive(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'float' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final Double _parseDouble(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
return jp.getDoubleValue();
}
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if (text.length() == 0) {
return (Double) getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return (Double) getNullValue(ctxt);
}
switch (text.charAt(0)) {
case 'I':
if (_isPosInf(text)) {
return Double.POSITIVE_INFINITY;
}
break;
case 'N':
if (_isNaN(text)) {
return Double.NaN;
}
break;
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> case '-':
if (_isNegInf(text)) {
return Double.NEGATIVE_INFINITY;
}
break;
}
try {
return parseDouble(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid Double value");
}
if (t == JsonToken.VALUE_NULL) {
return (Double) getNullValue(ctxt);
}
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final Double parsed = _parseDouble(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Double' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected final double _parseDoublePrimitive(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
// We accept couple of different types; obvious ones first:
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT || t == JsonToken.VALUE_NUMBER_FLOAT) { // coercing should work too
return jp.getDoubleValue();
}
// And finally, let's allow Strings to be converted too
if (t == JsonToken.VALUE_STRING) {
String text = jp.getText().trim();
if (text.length() == 0 || _hasTextualNull(text)) {
return 0.0;
}
switch (text.charAt(0)) {
case 'I':
if (_isPosInf(text)) {
return Double.POSITIVE_INFINITY;
}
break;
case 'N':
if (_isNaN(text)) {
return Double.NaN;
}
break;
case '-':
if (_isNegInf(text)) {
return Double.NEGATIVE_INFINITY;
}
break;
}
try {
return parseDouble(text);
} catch (IllegalArgumentException iae) { }
throw ctxt.weirdStringException(text, _valueClass, "not a valid double value");
}
if (t == JsonToken.VALUE_NULL) {
return 0.0;
}
// Issue#381
if (t == JsonToken.START_
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
jp.nextToken();
final double parsed = _parseDoublePrimitive(jp, ctxt);
t = jp.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(jp, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'Byte' value but there was more than a single value in the array");
}
return parsed;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, t);
}
protected java.util.Date _parseDate(JsonParser p, DeserializationContext ctxt)
throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_NUMBER_INT) {
return new java.util.Date(p.getLongValue());
}
if (t == JsonToken.VALUE_NULL) {
return (java.util.Date) getNullValue(ctxt);
}
if (t == JsonToken.VALUE_STRING) {
String value = null;
try {
// As per [JACKSON-203], take empty Strings to mean
value = p.getText().trim();
if (value.length() == 0) {
return (Date) getEmptyValue(ctxt);
}
if (_hasTextualNull(value)) {
return (java.util.Date) getNullValue(ctxt);
}
return ctxt.parseDate(value);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(value, _valueClass,
"not a valid representation (error: "+iae.getMessage()+")");
}
}
// [databind#381]
if (t == JsonToken.START_ARRAY) {
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Date parsed = _parseDate(p, ctxt);
t = p.nextToken();
if (t != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'java.util.Date' value but there was more than a single value in the array");
}
return parsed;
}
}
throw ctxt.mappingException(_valueClass, t);
}
/**
* Helper method for encapsulating calls to low-level double value parsing; single place
* just because we need a work
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>-around that must be applied to all calls.
*/
protected final static double parseDouble(String numStr) throws NumberFormatException
{
// avoid some nasty float representations... but should it be MIN_NORMAL or MIN_VALUE?
if (NumberInput.NASTY_SMALL_DOUBLE.equals(numStr)) {
return Double.MIN_NORMAL; // since 2.7; was MIN_VALUE prior
}
return Double.parseDouble(numStr);
}
/**
* Helper method used for accessing String value, if possible, doing
* necessary conversion or throwing exception as necessary.
*
* @since 2.1
*/
protected final String _parseString(JsonParser p, DeserializationContext ctxt) throws IOException
{
JsonToken t = p.getCurrentToken();
if (t == JsonToken.VALUE_STRING) {
return p.getText();
}
// [databind#381]
if (t == JsonToken.START_ARRAY && ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final String parsed = _parseString(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'String' value but there was more than a single value in the array");
}
return parsed;
}
String value = p.getValueAsString();
if (value != null) {
return value;
}
throw ctxt.mappingException(String.class, p.getCurrentToken());
}
/**
* Helper method that may be used to support fallback for Empty String / Empty Array
* non-standard representations; usually for things serialized as JSON Objects.
*
* @since 2.5
*/
protected T _deserializeFromEmpty(JsonParser jp, DeserializationContext ctxt)
throws IOException
{
JsonToken t = jp.getCurrentToken();
if (t == JsonToken.START_ARRAY) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT)) {
t = jp.nextToken();
if (t == JsonToken.END_ARRAY) {
return null;
}
throw ctxt.mappingException(handledType(), JsonToken.START_ARRAY);
}
} else if (t == JsonToken.VALUE_STRING) {
if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
String str = jp.getText().trim
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>();
if (str.isEmpty()) {
return null;
}
}
}
throw ctxt.mappingException(handledType());
}
/**
* Helper method called to determine if we are seeing String value of
* "null", and, further, that it should be coerced to null just like
* null token.
*
* @since 2.3
*/
protected boolean _hasTextualNull(String value) {
return "null".equals(value);
}
protected final boolean _isNegInf(String text) {
return "-Infinity".equals(text) || "-INF".equals(text);
}
protected final boolean _isPosInf(String text) {
return "Infinity".equals(text) || "INF".equals(text);
}
protected final boolean _isNaN(String text) { return "NaN".equals(text); }
/*
/****************************************************
/* Helper methods for sub-classes, coercions
/****************************************************
*/
/**
* Helper method called in case where an integral number is encountered, but
* config settings suggest that a coercion may be needed to "upgrade"
* {@link java.lang.Number} into "bigger" type like {@link java.lang.Long} or
* {@link java.math.BigInteger}
*
* @see DeserializationFeature#USE_BIG_INTEGER_FOR_INTS
* @see DeserializationFeature#USE_LONG_FOR_INTS
*
* @since 2.6
*/
protected Object _coerceIntegral(JsonParser p, DeserializationContext ctxt) throws IOException
{
int feats = ctxt.getDeserializationFeatures();
if (DeserializationFeature.USE_BIG_INTEGER_FOR_INTS.enabledIn(feats)) {
return p.getBigIntegerValue();
}
if (DeserializationFeature.USE_LONG_FOR_INTS.enabledIn(feats)) {
return p.getLongValue();
}
return p.getBigIntegerValue(); // should be optimal, whatever it is
}
/*
/****************************************************
/* Helper methods for sub-classes, resolving dependencies
/****************************************************
*/
/**
* Helper method used to locate deserializers for properties the
* type this deserializer handles contains (usually for properties of
* bean types)
*
* @param type Type of property to deserialize
* @param property Actual property object (field, method, constuctor parameter) used
* for passing deserialized values; provided so deserializer can be contextualized if necessary
*/
protected JsonDeserializer<Object> findDeserializer(DeserializationContext ctxt
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>,
JavaType type, BeanProperty property)
throws JsonMappingException
{
return ctxt.findContextualValueDeserializer(type, property);
}
/**
* Helper method to check whether given text refers to what looks like a clean simple
* integer number, consisting of optional sign followed by a sequence of digits.
*/
protected final boolean _isIntNumber(String text)
{
final int len = text.length();
if (len > 0) {
char c = text.charAt(0);
// skip leading sign (plus not allowed for strict JSON numbers but...)
int i = (c == '-' || c == '+') ? 1 : 0;
for (; i < len; ++i) {
int ch = text.charAt(i);
if (ch > '9' || ch < '0') {
return false;
}
}
return true;
}
return false;
}
/*
/**********************************************************
/* Helper methods for sub-classes, deserializer construction
/**********************************************************
*/
/**
* Helper method that can be used to see if specified property has annotation
* indicating that a converter is to be used for contained values (contents
* of structured types; array/List/Map values)
*
* @param existingDeserializer (optional) configured content
* serializer if one already exists.
*
* @since 2.2
*/
protected JsonDeserializer<?> findConvertingContentDeserializer(DeserializationContext ctxt,
BeanProperty prop, JsonDeserializer<?> existingDeserializer)
throws JsonMappingException
{
final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector();
if (intr != null && prop != null) {
AnnotatedMember member = prop.getMember();
if (member != null) {
Object convDef = intr.findDeserializationContentConverter(member);
if (convDef != null) {
Converter<Object,Object> conv = ctxt.converterInstance(prop.getMember(), convDef);
JavaType delegateType = conv.getInputType(ctxt.getTypeFactory());
if (existingDeserializer == null) {
existingDeserializer = ctxt.findContextualValueDeserializer(delegateType, prop);
}
return new StdDelegatingDeserializer<Object>(conv, delegateType, existingDeserializer);
}
}
}
return existingDeserializer;
}
/**
* Helper method that may be used to find if this deserializer has specific
* {@link JsonFormat} settings, either via property, or through type-specific
* defaulting.
*
* @param typeForDefaults Type (erased) used for finding default format settings
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>: allow unwrapping?
Boolean unwrapSingle = findFormatFeature(ctxt, property, String[].class,
JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY);
// Ok ok: if all we got is the default String deserializer, can just forget about it
if ((deser != null) && isDefaultDeserializer(deser)) {
deser = null;
}
if ((_elementDeserializer == deser) && (_unwrapSingle == unwrapSingle)) {
return this;
}
return new StringArrayDeserializer(deser, unwrapSingle);
}
@Override
public String[] deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!p.isExpectedStartArrayToken()) {
return handleNonArray(p, ctxt);
}
if (_elementDeserializer != null) {
return _deserializeCustom(p, ctxt);
}
final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] chunk = buffer.resetAndStart();
int ix = 0;
try {
while (true) {
String value = p.nextTextValue();
if (value == null) {
JsonToken t = p.getCurrentToken();
if (t == JsonToken.END_ARRAY) {
break;
}
if (t != JsonToken.VALUE_NULL) {
value = _parseString(p, ctxt);
}
}
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
}
chunk[ix++] = value;
}
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, chunk, buffer.bufferedSize() + ix);
}
String[] result = buffer.completeAndClearBuffer(chunk, ix, String.class);
ctxt.returnObjectBuffer(buffer);
return result;
}
/**
* Offlined version used when we do not use the default deserialization method.
*/
protected final String[] _deserializeCustom(JsonParser p, DeserializationContext ctxt) throws IOException
{
final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] chunk = buffer.resetAndStart();
final JsonDeserializer<String> deser = _elementDeserializer;
int ix = 0;
try {
while (true) {
/* 30-Dec-2014, tatu: This may look odd, but let's actually call method
* that suggest we are expecting a String; this helps with some formats,
* notably
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> XML. Note, however, that while we can get String, we can't
* assume that's what we use due to custom deserializer
*/
String value;
if (p.nextTextValue() == null) {
JsonToken t = p.getCurrentToken();
if (t == JsonToken.END_ARRAY) {
break;
}
// Ok: no need to convert Strings, but must recognize nulls
value = (t == JsonToken.VALUE_NULL) ? deser.getNullValue(ctxt) : deser.deserialize(p, ctxt);
} else {
value = deser.deserialize(p, ctxt);
}
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
}
chunk[ix++] = value;
}
} catch (Exception e) {
// note: pass String.class, not String[].class, as we need element type for error info
throw JsonMappingException.wrapWithPath(e, String.class, ix);
}
String[] result = buffer.completeAndClearBuffer(chunk, ix, String.class);
ctxt.returnObjectBuffer(buffer);
return result;
}
@Override
public Object deserializeWithType(JsonParser p, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
return typeDeserializer.deserializeTypedFromArray(p, ctxt);
}
private final String[] handleNonArray(JsonParser p, DeserializationContext ctxt) throws IOException
{
// implicit arrays from single values?
boolean canWrap = (_unwrapSingle == Boolean.TRUE) ||
((_unwrapSingle == null) &&
ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
if (canWrap) {
return new String[] { p.hasToken(JsonToken.VALUE_NULL) ? null : _parseString(p, ctxt) };
} else if (p.hasToken(JsonToken.VALUE_STRING)
&& ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
String str = p.getText();
if (str.length() == 0) {
return null;
}
}
throw ctxt.mappingException(_valueClass);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.type;
import java.lang.reflect.*;
import java.util.*;
import com.fasterxml.jackson.databind.JavaType;
/**
* Helper class used for resolving type parameters for given class
*/
public class TypeBindings
implements java.io.Serializable
{
private static final long serialVersionUID = 1L;
private final static String[] NO_STRINGS = new String[0];
private final static JavaType[] NO_TYPES = new JavaType[0];
private final static TypeBindings EMPTY = new TypeBindings(NO_STRINGS, NO_TYPES, null);
// // // Pre-resolved instances for minor optimizations
// // // Actual member information
/**
* Array of type (type variable) names.
*/
private final String[] _names;
/**
* Types matching names
*/
private final JavaType[] _types;
/**
* Names of potentially unresolved type variables.
*
* @since 2.3
*/
private final String[] _unboundVariables;
private final int _hashCode;
/*
/**********************************************************************
/* Construction
/**********************************************************************
*/
private TypeBindings(String[] names, JavaType[] types, String[] uvars)
{
_names = (names == null) ? NO_STRINGS : names;
_types = (types == null) ? NO_TYPES : types;
if (_names.length != _types.length) {
throw new IllegalArgumentException("Mismatching names ("+_names.length+"), types ("+_types.length+")");
}
int h = 1;
for (int i = 0, len = _types.length; i < len; ++i) {
h += _types[i].hashCode();
}
_unboundVariables = uvars;
_hashCode = h;
}
public static TypeBindings emptyBindings() {
return EMPTY;
}
// Let's just canonicalize serialized EMPTY back to static instance, if need be
protected Object readResolve() {
if ((_names == null) || (_names.length == 0)) {
return EMPTY;
}
return this;
}
/**
* Factory method for constructing bindings for given class using specified type
* parameters.
*/
public static TypeBindings create(Class<?> erasedType, List<JavaType> typeList)
{
JavaType[] types = (typeList == null || typeList.isEmpty()) ?
NO_TYPES : typeList.toArray(new JavaType[typeList.size()]);
return create(erasedType, types);
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> }
public static TypeBindings create(Class<?> erasedType, JavaType[] types)
{
if (types == null) {
types = NO_TYPES;
} else switch (types.length) {
case 1:
return create(erasedType, types[0]);
case 2:
return create(erasedType, types[0], types[1]);
}
TypeVariable<?>[] vars = erasedType.getTypeParameters();
String[] names;
if (vars == null || vars.length == 0) {
names = NO_STRINGS;
} else {
int len = vars.length;
names = new String[len];
for (int i = 0; i < len; ++i) {
names[i] = vars[i].getName();
}
}
// Check here to give better error message
if (names.length != types.length) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with "+types.length+" type parameter"
+((types.length == 1) ? "" : "s")+": class expects "+names.length);
}
return new TypeBindings(names, types, null);
}
public static TypeBindings create(Class<?> erasedType, JavaType typeArg1)
{
// 30-Oct-2015, tatu: Minor optimization for relatively common cases
TypeVariable<?>[] vars = TypeParamStash.paramsFor1(erasedType);
int varLen = (vars == null) ? 0 : vars.length;
if (varLen != 1) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with 1 type parameter: class expects "+varLen);
}
return new TypeBindings(new String[] { vars[0].getName() },
new JavaType[] { typeArg1 }, null);
}
public static TypeBindings create(Class<?> erasedType, JavaType typeArg1, JavaType typeArg2)
{
// 30-Oct-2015, tatu: Minor optimization for relatively common cases
TypeVariable<?>[] vars = TypeParamStash.paramsFor2(erasedType);
int varLen = (vars == null) ? 0 : vars.length;
if (varLen != 2) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with 2 type parameters: class expects "+varLen);
}
return new
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> TypeBindings(new String[] { vars[0].getName(), vars[1].getName() },
new JavaType[] { typeArg1, typeArg2 }, null);
}
/**
* Alternate factory method that may be called if it is possible that type
* does or does not require type parameters; this is mostly useful for
* collection- and map-like types.
*/
public static TypeBindings createIfNeeded(Class<?> erasedType, JavaType typeArg1)
{
TypeVariable<?>[] vars = erasedType.getTypeParameters();
int varLen = (vars == null) ? 0 : vars.length;
if (varLen == 0) {
return EMPTY;
}
if (varLen != 1) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with 1 type parameter: class expects "+varLen);
}
return new TypeBindings(new String[] { vars[0].getName() },
new JavaType[] { typeArg1 }, null);
}
/**
* Alternate factory method that may be called if it is possible that type
* does or does not require type parameters; this is mostly useful for
* collection- and map-like types.
*/
public static TypeBindings createIfNeeded(Class<?> erasedType, JavaType[] types)
{
TypeVariable<?>[] vars = erasedType.getTypeParameters();
if (vars == null || vars.length == 0) {
return EMPTY;
}
if (types == null) {
types = NO_TYPES;
}
int len = vars.length;
String[] names = new String[len];
for (int i = 0; i < len; ++i) {
names[i] = vars[i].getName();
}
// Check here to give better error message
if (names.length != types.length) {
throw new IllegalArgumentException("Can not create TypeBindings for class "+erasedType.getName()
+" with "+types.length+" type parameter"
+((types.length == 1) ? "" : "s")+": class expects "+names.length);
}
return new TypeBindings(names, types, null);
}
/**
* Method for creating an instance that has same bindings as this object,
* plus an indicator for additional type variable that may be unbound within
* this context; this is needed to resolve recursive self-references.
*/
public TypeBindings withUnboundVariable(String name)
{
int len = (_unboundVariables == null) ? 0
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> : _unboundVariables.length;
String[] names = (len == 0)
? new String[1] : Arrays.copyOf(_unboundVariables, len+1);
names[len] = name;
return new TypeBindings(_names, _types, names);
}
/*
/**********************************************************************
/* Accessors
/**********************************************************************
*/
/**
* Find type bound to specified name, if there is one; returns bound type if so, null if not.
*/
public JavaType findBoundType(String name)
{
for (int i = 0, len = _names.length; i < len; ++i) {
if (name.equals(_names[i])) {
JavaType t = _types[i];
if (t instanceof ResolvedRecursiveType) {
ResolvedRecursiveType rrt = (ResolvedRecursiveType) t;
JavaType t2 = rrt.getSelfReferencedType();
if (t2 != null) {
t = t2;
} else {
/* 25-Feb-2016, tatu: Looks like a potential problem, but alas
* we have a test where this should NOT fail and things... seem
* to work. So be it.
*/
/*
throw new IllegalStateException(String.format
("Unresolved ResolvedRecursiveType for parameter '%s' (index #%d; erased type %s)",
name, i, t.getRawClass()));
*/
}
}
return t;
}
}
return null;
}
public boolean isEmpty() {
return (_types.length == 0);
}
/**
* Returns number of bindings contained
*/
public int size() {
return _types.length;
}
public String getBoundName(int index)
{
if (index < 0 || index >= _names.length) {
return null;
}
return _names[index];
}
public JavaType getBoundType(int index)
{
if (index < 0 || index >= _types.length) {
return null;
}
return _types[index];
}
/**
* Accessor for getting bound types in declaration order
*/
public List<JavaType> getTypeParameters()
{
if (_types.length == 0) {
return Collections.emptyList();
}
return Arrays.asList(_types);
}
/**
* @since 2.3
*/
public boolean hasUnbound(String name) {
if (_unboundVariables != null) {
for (int i =
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> _unboundVariables.length; --i >= 0; ) {
if (name.equals(_unboundVariables[i])) {
return true;
}
}
}
return false;
}
/**
* Factory method that will create an object that can be used as a key for
* caching purposes by {@link TypeFactory}
*
* @since 2.8
*/
public Object asKey(Class<?> rawBase) {
// safe to pass _types array without copy since it is not exposed via
// any access, nor modified by this class
return new AsKey(rawBase, _types, _hashCode);
}
/*
/**********************************************************************
/* Standard methods
/**********************************************************************
*/
@Override public String toString()
{
if (_types.length == 0) {
return "<>";
}
StringBuilder sb = new StringBuilder();
sb.append('<');
for (int i = 0, len = _types.length; i < len; ++i) {
if (i > 0) {
sb.append(',');
}
// sb = _types[i].appendBriefDescription(sb);
String sig = _types[i].getGenericSignature();
sb.append(sig);
}
sb.append('>');
return sb.toString();
}
@Override public int hashCode() { return _hashCode; }
@Override public boolean equals(Object o)
{
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
TypeBindings other = (TypeBindings) o;
int len = _types.length;
if (len != other.size()) {
return false;
}
JavaType[] otherTypes = other._types;
for (int i = 0; i < len; ++i) {
if (!otherTypes[i].equals(_types[i])) {
return false;
}
}
return true;
}
/*
/**********************************************************************
/* Package accessible methods
/**********************************************************************
*/
protected JavaType[] typeParameterArray() {
return _types;
}
/*
/**********************************************************************
/* Helper classes
/**********************************************************************
*/
// 30-Oct-2015, tatu: Surprising, but looks like type parameters access can be bit of
// a hot spot. So avoid for a small number of common generic types. Note that we do
// need both common abstract types and concrete ones; latter for specialization
/**
* Helper class that contains simple logic for avoiding repeated look
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>raw = raw ;
_params = params;
_hash = hash;
}
@Override
public int hashCode() { return _hash; }
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null) return false;
if (o.getClass() != getClass()) return false;
AsKey other = (AsKey) o;
if ((_hash == other._hash) && (_raw == other._raw)) {
final JavaType[] otherParams = other._params;
final int len = _params.length;
if (len == otherParams.length) {
for (int i = 0; i < len; ++i) {
if (!_params[i].equals(otherParams[i])) {
return false;
}
}
return true;
}
}
return false;
}
@Override
public String toString() {
return _raw.getName()+"<>";
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.NumberOutput;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Numeric node that contains simple 32-bit integer values.
*/
public class IntNode
extends NumericNode
{
// // // Let's cache small set of common value
final static int MIN_CANONICAL = -1;
final static int MAX_CANONICAL = 10;
private final static IntNode[] CANONICALS;
static {
int count = MAX_CANONICAL - MIN_CANONICAL + 1;
CANONICALS = new IntNode[count];
for (int i = 0; i < count; ++i) {
CANONICALS[i] = new IntNode(MIN_CANONICAL + i);
}
}
/**
* Integer value this node contains
*/
protected final int _value;
/*
************************************************
* Construction
************************************************
*/
public IntNode(int v) { _value = v; }
public static IntNode valueOf(int i) {
if (i > MAX_CANONICAL || i < MIN_CANONICAL) return new IntNode(i);
return CANONICALS[i - MIN_CANONICAL];
}
/*
/**********************************************************
/* BaseJsonNode extended API
/**********************************************************
*/
@Override public JsonToken asToken() { return JsonToken.VALUE_NUMBER_INT; }
@Override
public JsonParser.NumberType numberType() { return JsonParser.NumberType.INT; }
/*
/**********************************************************
/* Overrridden JsonNode methods
/**********************************************************
*/
@Override
public boolean isIntegralNumber() { return true; }
@Override
public boolean isInt() { return true; }
@Override public boolean canConvertToInt() { return true; }
@Override public boolean canConvertToLong() { return true; }
@Override
public Number numberValue() {
return Integer.valueOf(_value);
}
@Override
public short shortValue() { return (short) _value; }
@Override
public int intValue() { return _value; }
@Override
public long longValue() { return (long) _value; }
@Override
public float floatValue() { return (float) _value; }
@Override
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Class<?> rawType, JavaType keyT,
JavaType valueT) {
// First: may need to fabricate TypeBindings (needed for refining into
// concrete collection types, as per [databind#1102])
TypeVariable<?>[] vars = rawType.getTypeParameters();
TypeBindings bindings;
if ((vars == null) || (vars.length != 2)) {
bindings = TypeBindings.emptyBindings();
} else {
bindings = TypeBindings.create(rawType, keyT, valueT);
}
return new MapLikeType(rawType, bindings, _bogusSuperClass(rawType),
null, keyT, valueT, null, null, false);
}
@Deprecated
// since 2.7
@Override
protected JavaType _narrow(Class<?> subclass) {
return new MapLikeType(subclass, _bindings, _superClass,
_superInterfaces, _keyType, _valueType, _valueHandler,
_typeHandler, _asStatic);
}
/**
* @since 2.7
*/
public MapLikeType withKeyType(JavaType keyType) {
if (keyType == _keyType) {
return this;
}
return new MapLikeType(_class, _bindings, _superClass,
_superInterfaces, keyType, _valueType, _valueHandler,
_typeHandler, _asStatic);
}
@Override
public JavaType withContentType(JavaType contentType) {
if (_valueType == contentType) {
return this;
}
return new MapLikeType(_class, _bindings, _superClass,
_superInterfaces, _keyType, contentType, _valueHandler,
_typeHandler, _asStatic);
}
@Override
public MapLikeType withTypeHandler(Object h) {
return new MapLikeType(_class, _bindings, _superClass,
_superInterfaces, _keyType, _valueType, _valueHandler, h,
_asStatic);
}
@Override
public MapLikeType withContentTypeHandler(Object h) {
return new MapLikeType(_class, _bindings, _superClass,
_superInterfaces, _keyType, _valueType.withTypeHandler(h),
_valueHandler, _typeHandler, _asStatic);
}
@Override
public MapLikeType withValueHandler(Object h) {
return new MapLikeType(_class, _bindings, _superClass,
_superInterfaces, _keyType, _valueType, h, _typeHandler,
_asStatic);
}
@Override
public MapLike
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> this node is numeric ({@link #isNumber} returns true). For other
* types returns 0.0.
* For integer values, conversion is done using coercion; this means
* that an overflow is possible for `long` values
*
* @return 32-bit float value this node contains, if any; 0.0 for non-number nodes.
*
* @since 2.2
*/
public float floatValue() { return 0.0f; }
/**
* Returns 64-bit floating point (double) value for this node, <b>if and only if</b>
* this node is numeric ({@link #isNumber} returns true). For other
* types returns 0.0.
* For integer values, conversion is done using coercion; this may result
* in overflows with {@link BigInteger} values.
*
* @return 64-bit double value this node contains, if any; 0.0 for non-number nodes.
*
* @since 2.2
*/
public double doubleValue() { return 0.0; }
public BigDecimal decimalValue() { return BigDecimal.ZERO; }
public BigInteger bigIntegerValue() { return BigInteger.ZERO; }
/*
/**********************************************************
/* Public API, value access with conversion(s)/coercion(s)
/**********************************************************
*/
/**
* Method that will return a valid String representation of
* the container value, if the node is a value node
* (method {@link #isValueNode} returns true),
* otherwise empty String.
*/
public abstract String asText();
/**
* Method similar to {@link #asText()}, except that it will return
* <code>defaultValue</code> in cases where null value would be returned;
* either for missing nodes (trying to access missing property, or element
* at invalid item for array) or explicit nulls.
*
* @since 2.4
*/
public String asText(String defaultValue) {
String str = asText();
return (str == null) ? defaultValue : str;
}
/**
* Method that will try to convert value of this node to a Java <b>int</b>.
* Numbers are coerced using default Java rules; booleans convert to 0 (false)
* and 1 (true), and Strings are parsed using default Java language integer
* parsing rules.
*<p>
* If representation can not be converted to an int (including structured types
* like Objects and Arrays),
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Base(BeanSerializerBase src,
ObjectIdWriter objectIdWriter)
{
this(src, objectIdWriter, src._propertyFilterId);
}
/**
* @since 2.3
*/
protected BeanSerializerBase(BeanSerializerBase src,
ObjectIdWriter objectIdWriter, Object filterId)
{
super(src._handledType);
_props = src._props;
_filteredProps = src._filteredProps;
_typeId = src._typeId;
_anyGetterWriter = src._anyGetterWriter;
_objectIdWriter = objectIdWriter;
_propertyFilterId = filterId;
_serializationShape = src._serializationShape;
}
protected BeanSerializerBase(BeanSerializerBase src, String[] toIgnore)
{
super(src._handledType);
// Bit clumsy, but has to do:
HashSet<String> ignoredSet = ArrayBuilders.arrayToSet(toIgnore);
final BeanPropertyWriter[] propsIn = src._props;
final BeanPropertyWriter[] fpropsIn = src._filteredProps;
final int len = propsIn.length;
ArrayList<BeanPropertyWriter> propsOut = new ArrayList<BeanPropertyWriter>(len);
ArrayList<BeanPropertyWriter> fpropsOut = (fpropsIn == null) ? null : new ArrayList<BeanPropertyWriter>(len);
for (int i = 0; i < len; ++i) {
BeanPropertyWriter bpw = propsIn[i];
// should be ignored?
if (ignoredSet.contains(bpw.getName())) {
continue;
}
propsOut.add(bpw);
if (fpropsIn != null) {
fpropsOut.add(fpropsIn[i]);
}
}
_props = propsOut.toArray(new BeanPropertyWriter[propsOut.size()]);
_filteredProps = (fpropsOut == null) ? null : fpropsOut.toArray(new BeanPropertyWriter[fpropsOut.size()]);
_typeId = src._typeId;
_anyGetterWriter = src._anyGetterWriter;
_objectIdWriter = src._objectIdWriter;
_propertyFilterId = src._propertyFilterId;
_serializationShape = src._serializationShape;
}
/**
* Mutant factory used for creating a new instance with different
* {@link ObjectIdWriter}.
*
* @since 2.0
*/
public abstract BeanSerializerBase withObjectIdWriter(ObjectIdWriter objectIdWriter);
/**
* Mutant factory used for creating a new instance with additional
* set of properties to ignore (from properties this instance otherwise
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> has)
*
* @since 2.0
*/
protected abstract BeanSerializerBase withIgnorals(String[] toIgnore);
/**
* Mutant factory for creating a variant that output POJO as a
* JSON Array. Implementations may ignore this request if output
* as array is not possible (either at all, or reliably).
*
* @since 2.1
*/
protected abstract BeanSerializerBase asArraySerializer();
/**
* Mutant factory used for creating a new instance with different
* filter id (used with <code>JsonFilter</code> annotation)
*
* @since 2.3
*/
@Override
public abstract BeanSerializerBase withFilterId(Object filterId);
/**
* Copy-constructor that is useful for sub-classes that just want to
* copy all super-class properties without modifications.
*/
protected BeanSerializerBase(BeanSerializerBase src) {
this(src, src._props, src._filteredProps);
}
/**
* Copy-constructor that will also rename properties with given prefix
* (if it's non-empty)
*/
protected BeanSerializerBase(BeanSerializerBase src, NameTransformer unwrapper) {
this(src, rename(src._props, unwrapper), rename(src._filteredProps, unwrapper));
}
private final static BeanPropertyWriter[] rename(BeanPropertyWriter[] props,
NameTransformer transformer)
{
if (props == null || props.length == 0 || transformer == null || transformer == NameTransformer.NOP) {
return props;
}
final int len = props.length;
BeanPropertyWriter[] result = new BeanPropertyWriter[len];
for (int i = 0; i < len; ++i) {
BeanPropertyWriter bpw = props[i];
if (bpw != null) {
result[i] = bpw.rename(transformer);
}
}
return result;
}
/*
/**********************************************************
/* Post-constriction processing: resolvable, contextual
/**********************************************************
*/
/**
* We need to implement {@link ResolvableSerializer} to be able to
* properly handle cyclic type references.
*/
@Override
public void resolve(SerializerProvider provider)
throws JsonMappingException
{
int filteredCount = (_filteredProps == null) ? 0 : _filteredProps.length;
for (int i = 0, len = _props.length; i < len; ++i) {
BeanPropertyWriter prop = _props[i];
// let's start with null serializer resolution actually
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
if (!prop.willSuppressNulls() && !prop.hasNullSerializer()) {
JsonSerializer<Object> nullSer = provider.findNullValueSerializer(prop);
if (nullSer != null) {
prop.assignNullSerializer(nullSer);
// also: remember to replace filtered property too? (see [JACKSON-364])
if (i < filteredCount) {
BeanPropertyWriter w2 = _filteredProps[i];
if (w2 != null) {
w2.assignNullSerializer(nullSer);
}
}
}
}
if (prop.hasSerializer()) {
continue;
}
// [databind#124]: allow use of converters
JsonSerializer<Object> ser = findConvertingSerializer(provider, prop);
if (ser == null) {
// Was the serialization type hard-coded? If so, use it
JavaType type = prop.getSerializationType();
// It not, we can use declared return type if and only if declared type is final:
// if not, we don't really know the actual type until we get the instance.
if (type == null) {
// 30-Oct-2015, tatu: Not sure why this was used
// type = provider.constructType(prop.getGenericPropertyType());
// but this looks better
type = prop.getType();
if (!type.isFinal()) {
if (type.isContainerType() || type.containedTypeCount() > 0) {
prop.setNonTrivialBaseType(type);
}
continue;
}
}
ser = provider.findValueSerializer(type, prop);
/* 04-Feb-2010, tatu: We may have stashed type serializer for content types
* too, earlier; if so, it's time to connect the dots here:
*/
if (type.isContainerType()) {
TypeSerializer typeSer = type.getContentType().getTypeHandler();
if (typeSer != null) {
// for now, can do this only for standard containers...
if (ser instanceof ContainerSerializer<?>) {
// ugly casts... but necessary
@SuppressWarnings("unchecked")
JsonSerializer<Object> ser2 = (JsonSerializer<Object>)((ContainerSerializer<?>) ser).withValueTypeSerializer(typeSer);
ser = ser2;
}
}
}
}
prop.assignSerializer(ser);
// and maybe replace filtered property too? (see [JACKSON-364])
if (i < filteredCount) {
BeanPropertyWriter
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> w2 = _filteredProps[i];
if (w2 != null) {
w2.assignSerializer(ser);
}
}
}
// also, any-getter may need to be resolved
if (_anyGetterWriter != null) {
// 23-Feb-2015, tatu: Misleading, as this actually triggers call to contextualization...
_anyGetterWriter.resolve(provider);
}
}
/**
* Helper method that can be used to see if specified property is annotated
* to indicate use of a converter for property value (in case of container types,
* it is container type itself, not key or content type).
*
* @since 2.2
*/
protected JsonSerializer<Object> findConvertingSerializer(SerializerProvider provider,
BeanPropertyWriter prop)
throws JsonMappingException
{
final AnnotationIntrospector intr = provider.getAnnotationIntrospector();
if (intr != null) {
AnnotatedMember m = prop.getMember();
if (m != null) {
Object convDef = intr.findSerializationConverter(m);
if (convDef != null) {
Converter<Object,Object> conv = provider.converterInstance(prop.getMember(), convDef);
JavaType delegateType = conv.getOutputType(provider.getTypeFactory());
// [databind#731]: Should skip if nominally java.lang.Object
JsonSerializer<?> ser = delegateType.isJavaLangObject() ? null
: provider.findValueSerializer(delegateType, prop);
return new StdDelegatingSerializer(conv, delegateType, ser);
}
}
}
return null;
}
@SuppressWarnings("incomplete-switch")
@Override
public JsonSerializer<?> createContextual(SerializerProvider provider,
BeanProperty property)
throws JsonMappingException
{
final AnnotationIntrospector intr = provider.getAnnotationIntrospector();
final AnnotatedMember accessor = (property == null || intr == null)
? null : property.getMember();
final SerializationConfig config = provider.getConfig();
// Let's start with one big transmutation: Enums that are annotated
// to serialize as Objects may want to revert
JsonFormat.Shape shape = null;
if (accessor != null) {
JsonFormat.Value format = intr.findFormat((Annotated) accessor);
if (format != null) {
shape = format.getShape();
// or, alternatively, asked to revert "back to" other representations...
if (shape != _serializationShape) {
if (_handledType.isEnum()) {
switch (shape)
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> {
case STRING:
case NUMBER:
case NUMBER_INT:
// 12-Oct-2014, tatu: May need to introspect full annotations... but
// for now, just do class ones
BeanDescription desc = config.introspectClassAnnotations(_handledType);
JsonSerializer<?> ser = EnumSerializer.construct(_handledType,
provider.getConfig(), desc, format);
return provider.handlePrimaryContextualization(ser, property);
}
}
}
}
}
ObjectIdWriter oiw = _objectIdWriter;
String[] ignorals = null;
Object newFilterId = null;
// Then we may have an override for Object Id
if (accessor != null) {
ignorals = intr.findPropertiesToIgnore(accessor, true);
ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor);
if (objectIdInfo == null) {
// no ObjectId override, but maybe ObjectIdRef?
if (oiw != null) {
objectIdInfo = intr.findObjectReferenceInfo(accessor,
new ObjectIdInfo(NAME_FOR_OBJECT_REF, null, null, null));
oiw = _objectIdWriter.withAlwaysAsId(objectIdInfo.getAlwaysAsId());
}
} else {
/* Ugh: mostly copied from BeanSerializerBase: but can't easily
* change it to be able to move to SerializerProvider (where it
* really belongs)
*/
// 2.1: allow modifications by "id ref" annotations as well:
objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo);
ObjectIdGenerator<?> gen;
Class<?> implClass = objectIdInfo.getGeneratorType();
JavaType type = provider.constructType(implClass);
JavaType idType = provider.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0];
// Property-based generator is trickier
if (implClass == ObjectIdGenerators.PropertyGenerator.class) { // most special one, needs extra work
String propName = objectIdInfo.getPropertyName().getSimpleName();
BeanPropertyWriter idProp = null;
for (int i = 0, len = _props.length ;; ++i) {
if (i == len) {
throw new IllegalArgumentException("Invalid Object Id definition for "+_handledType.getName()
+": can not find property with name '"+propName+"'");
}
BeanPropertyWriter prop = _props[i];
if (propName.equals(prop.getName())) {
idProp = prop;
/* Let's force it to be the first
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> property to output
* (although it may still get rearranged etc)
*/
if (i > 0) { // note: must shuffle both regular properties and filtered
System.arraycopy(_props, 0, _props, 1, i);
_props[0] = idProp;
if (_filteredProps != null) {
BeanPropertyWriter fp = _filteredProps[i];
System.arraycopy(_filteredProps, 0, _filteredProps, 1, i);
_filteredProps[0] = fp;
}
}
break;
}
}
idType = idProp.getType();
gen = new PropertyBasedObjectIdGenerator(objectIdInfo, idProp);
oiw = ObjectIdWriter.construct(idType, (PropertyName) null, gen, objectIdInfo.getAlwaysAsId());
} else { // other types need to be simpler
gen = provider.objectIdGeneratorInstance(accessor, objectIdInfo);
oiw = ObjectIdWriter.construct(idType, objectIdInfo.getPropertyName(), gen,
objectIdInfo.getAlwaysAsId());
}
}
// Or change Filter Id in use?
Object filterId = intr.findFilterId(accessor);
if (filterId != null) {
// but only consider case of adding a new filter id (no removal via annotation)
if (_propertyFilterId == null || !filterId.equals(_propertyFilterId)) {
newFilterId = filterId;
}
}
}
// either way, need to resolve serializer:
BeanSerializerBase contextual = this;
if (oiw != null) {
JsonSerializer<?> ser = provider.findValueSerializer(oiw.idType, property);
oiw = oiw.withSerializer(ser);
if (oiw != _objectIdWriter) {
contextual = contextual.withObjectIdWriter(oiw);
}
}
// And possibly add more properties to ignore
if (ignorals != null && ignorals.length != 0) {
contextual = contextual.withIgnorals(ignorals);
}
if (newFilterId != null) {
contextual = contextual.withFilterId(newFilterId);
}
if (shape == null) {
shape = _serializationShape;
}
if (shape == JsonFormat.Shape.ARRAY) {
return contextual.asArraySerializer();
}
return contextual;
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public Iterator<PropertyWriter> properties() {
return Arrays
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>();
}
}
protected final void _serializeWithObjectId(Object bean, JsonGenerator gen, SerializerProvider provider,
TypeSerializer typeSer) throws IOException
{
final ObjectIdWriter w = _objectIdWriter;
WritableObjectId objectId = provider.findObjectId(bean, w.generator);
// If possible, write as id already
if (objectId.writeAsId(gen, provider, w)) {
return;
}
// If not, need to inject the id:
Object id = objectId.generateId(bean);
if (w.alwaysAsId) {
w.serializer.serialize(id, gen, provider);
return;
}
_serializeObjectId(bean, gen, provider, typeSer, objectId);
}
protected void _serializeObjectId(Object bean, JsonGenerator gen,SerializerProvider provider,
TypeSerializer typeSer, WritableObjectId objectId) throws IOException
{
final ObjectIdWriter w = _objectIdWriter;
String typeStr = (_typeId == null) ? null :_customTypeId(bean);
if (typeStr == null) {
typeSer.writeTypePrefixForObject(bean, gen);
} else {
typeSer.writeCustomTypePrefixForObject(bean, gen, typeStr);
}
objectId.writeAsField(gen, provider, w);
if (_propertyFilterId != null) {
serializeFieldsFiltered(bean, gen, provider);
} else {
serializeFields(bean, gen, provider);
}
if (typeStr == null) {
typeSer.writeTypeSuffixForObject(bean, gen);
} else {
typeSer.writeCustomTypeSuffixForObject(bean, gen, typeStr);
}
}
protected final String _customTypeId(Object bean)
{
final Object typeId = _typeId.getValue(bean);
if (typeId == null) {
return "";
}
return (typeId instanceof String) ? (String) typeId : typeId.toString();
}
/*
/**********************************************************
/* Field serialization methods
/**********************************************************
*/
protected void serializeFields(Object bean, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final BeanPropertyWriter[] props;
if (_filteredProps != null && provider.getActiveView() != null) {
props = _filteredProps;
} else {
props = _props;
}
int i = 0;
try {
for (final int len = props.length; i < len; ++i) {
BeanPropertyWriter prop = props[i];
if (prop != null
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>) { // can have nulls in filtered list
prop.serializeAsField(bean, gen, provider);
}
}
if (_anyGetterWriter != null) {
_anyGetterWriter.getAndSerialize(bean, gen, provider);
}
} catch (Exception e) {
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
wrapAndThrow(provider, e, bean, name);
} catch (StackOverflowError e) {
/* 04-Sep-2009, tatu: Dealing with this is tricky, since we do not
* have many stack frames to spare... just one or two; can't
* make many calls.
*/
// 10-Dec-2015, tatu: and due to above, avoid "from" method, call ctor directly:
//JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e);
JsonMappingException mapE = new JsonMappingException(gen, "Infinite recursion (StackOverflowError)", e);
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
mapE.prependPath(new JsonMappingException.Reference(bean, name));
throw mapE;
}
}
/**
* Alternative serialization method that gets called when there is a
* {@link PropertyFilter} that needs to be called to determine
* which properties are to be serialized (and possibly how)
*/
protected void serializeFieldsFiltered(Object bean, JsonGenerator gen,
SerializerProvider provider)
throws IOException, JsonGenerationException
{
/* note: almost verbatim copy of "serializeFields"; copied (instead of merged)
* so that old method need not add check for existence of filter.
*/
final BeanPropertyWriter[] props;
if (_filteredProps != null && provider.getActiveView() != null) {
props = _filteredProps;
} else {
props = _props;
}
final PropertyFilter filter = findPropertyFilter(provider, _propertyFilterId, bean);
// better also allow missing filter actually..
if (filter == null) {
serializeFields(bean, gen, provider);
return;
}
int i = 0;
try {
for (final int len = props.length; i < len; ++i) {
BeanPropertyWriter prop = props[i];
if (prop != null) { // can have nulls in filtered list
filter.serializeAsField(bean, gen, provider,
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> prop);
}
}
if (_anyGetterWriter != null) {
_anyGetterWriter.getAndFilter(bean, gen, provider, filter);
}
} catch (Exception e) {
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
wrapAndThrow(provider, e, bean, name);
} catch (StackOverflowError e) {
// Minimize call depth since we are close to fail:
//JsonMappingException mapE = JsonMappingException.from(gen, "Infinite recursion (StackOverflowError)", e);
JsonMappingException mapE = new JsonMappingException(gen, "Infinite recursion (StackOverflowError)", e);
String name = (i == props.length) ? "[anySetter]" : props[i].getName();
mapE.prependPath(new JsonMappingException.Reference(bean, name));
throw mapE;
}
}
@Deprecated
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("object", true);
// [JACKSON-813]: Add optional JSON Schema id attribute, if found
// NOTE: not optimal, does NOT go through AnnotationIntrospector etc:
JsonSerializableSchema ann = _handledType.getAnnotation(JsonSerializableSchema.class);
if (ann != null) {
String id = ann.id();
if (id != null && id.length() > 0) {
o.put("id", id);
}
}
//todo: should the classname go in the title?
//o.put("title", _className);
ObjectNode propertiesNode = o.objectNode();
final PropertyFilter filter;
if (_propertyFilterId != null) {
filter = findPropertyFilter(provider, _propertyFilterId, null);
} else {
filter = null;
}
for (int i = 0; i < _props.length; i++) {
BeanPropertyWriter prop = _props[i];
if (filter == null) {
prop.depositSchemaProperty(propertiesNode, provider);
} else {
filter.depositSchemaProperty(prop, propertiesNode, provider);
}
}
o.set("properties", propertiesNode);
return o;
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
//deposit your output format
if (visitor == null) {
return;
}
JsonObjectFormatVisitor objectVisitor = visitor.
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>expectObjectFormat(typeHint);
if (objectVisitor == null) {
return;
}
final SerializerProvider provider = visitor.getProvider();
if (_propertyFilterId != null) {
PropertyFilter filter = findPropertyFilter(visitor.getProvider(),
_propertyFilterId, null);
for (int i = 0, end = _props.length; i < end; ++i) {
filter.depositSchemaProperty(_props[i], objectVisitor, provider);
}
} else {
Class<?> view = ((_filteredProps == null) || (provider == null))
? null : provider.getActiveView();
final BeanPropertyWriter[] props;
if (view != null) {
props = _filteredProps;
} else {
props = _props;
}
for (int i = 0, end = props.length; i < end; ++i) {
BeanPropertyWriter prop = props[i];
if (prop != null) { // may be filtered out unconditionally
prop.depositSchemaProperty(objectVisitor, provider);
}
}
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind;
import java.io.*;
import java.util.*;
import static org.junit.Assert.*;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer;
import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer;
import com.fasterxml.jackson.databind.type.TypeFactory;
public abstract class BaseMapTest
extends BaseTest
{
private final static Object SINGLETON_OBJECT = new Object();
/*
/**********************************************************
/* Shared helper classes
/**********************************************************
*/
/**
* Simple wrapper around boolean types, usually to test value
* conversions or wrapping
*/
protected static class BooleanWrapper {
public Boolean b;
@JsonCreator
public BooleanWrapper(Boolean value) { b = value; }
@JsonValue public Boolean value() { return b; }
}
protected static class IntWrapper {
public int i;
public IntWrapper() { }
public IntWrapper(int value) { i = value; }
}
protected static class LongWrapper {
public long l;
public LongWrapper() { }
public LongWrapper(long value) { l = value; }
}
/**
* Simple wrapper around String type, usually to test value
* conversions or wrapping
*/
protected static class StringWrapper {
public String str;
public StringWrapper() { }
public StringWrapper(String value) {
str = value;
}
}
protected static class ObjectWrapper {
private final Object object;
protected ObjectWrapper(final Object object) {
this.object = object;
}
public Object getObject() { return object; }
@JsonCreator
static ObjectWrapper jsonValue(final Object object) {
return new ObjectWrapper(object);
}
}
protected static class ListWrapper<T>
{
public List<T> list;
public ListWrapper(@SuppressWarnings("unchecked") T... values) {
list = new ArrayList<T>();
for (T value : values) {
list.add(value);
}
}
}
protected static class MapWrapper<K,V>
{
public Map<K,V> map;
public MapWrapper(Map<K,V> m) {
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>(o.equals(o));
assertFalse(o.equals(null));
assertFalse(o.equals(SINGLETON_OBJECT));
// just for fun, let's also call hash code...
o.hashCode();
}
/*
/**********************************************************
/* Helper methods, serialization
/**********************************************************
*/
@SuppressWarnings("unchecked")
protected Map<String,Object> writeAndMap(ObjectMapper m, Object value)
throws IOException
{
String str = m.writeValueAsString(value);
return (Map<String,Object>) m.readValue(str, Map.class);
}
protected String serializeAsString(ObjectMapper m, Object value)
throws IOException
{
return m.writeValueAsString(value);
}
protected String serializeAsString(Object value)
throws IOException
{
return serializeAsString(SHARED_MAPPER, value);
}
protected String asJSONObjectValueString(Object... args)
throws IOException
{
return asJSONObjectValueString(SHARED_MAPPER, args);
}
protected String asJSONObjectValueString(ObjectMapper m, Object... args)
throws IOException
{
LinkedHashMap<Object,Object> map = new LinkedHashMap<Object,Object>();
for (int i = 0, len = args.length; i < len; i += 2) {
map.put(args[i], args[i+1]);
}
return m.writeValueAsString(map);
}
/*
/**********************************************************
/* Helper methods, deserialization
/**********************************************************
*/
protected <T> T readAndMapFromString(String input, Class<T> cls)
throws IOException
{
return readAndMapFromString(SHARED_MAPPER, input, cls);
}
protected <T> T readAndMapFromString(ObjectMapper m, String input, Class<T> cls) throws IOException
{
return (T) m.readValue("\""+input+"\"", cls);
}
/*
/**********************************************************
/* Helper methods, other
/**********************************************************
*/
protected TimeZone getUTCTimeZone() {
return TimeZone.getTimeZone("GMT");
}
protected byte[] utf8Bytes(String str) {
try {
return str.getBytes("UTF-8");
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
protected static String aposToQuotes(String json) {
return json.replace("'", "\"");
}
protected static String quotesToApos(String json) {
return json.replace("\"", "'");
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.io.CharTypes;
import com.fasterxml.jackson.core.io.NumberInput;
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
import com.fasterxml.jackson.databind.SerializerProvider;
/**
* Value node that contains a text value.
*/
public class TextNode
extends ValueNode
{
final static TextNode EMPTY_STRING_NODE = new TextNode("");
protected final String _value;
public TextNode(String v) { _value = v; }
/**
* Factory method that should be used to construct instances.
* For some common cases, can reuse canonical instances: currently
* this is the case for empty Strings, in future possible for
* others as well. If null is passed, will return null.
*
* @return Resulting {@link TextNode} object, if <b>v</b>
* is NOT null; null if it is.
*/
public static TextNode valueOf(String v)
{
if (v == null) {
return null;
}
if (v.length() == 0) {
return EMPTY_STRING_NODE;
}
return new TextNode(v);
}
@Override
public JsonNodeType getNodeType() {
return JsonNodeType.STRING;
}
@Override public JsonToken asToken() { return JsonToken.VALUE_STRING; }
@Override
public String textValue() {
return _value;
}
/**
* Method for accessing textual contents assuming they were
* base64 encoded; if so, they are decoded and resulting binary
* data is returned.
*/
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException
{
@SuppressWarnings("resource")
ByteArrayBuilder builder = new ByteArrayBuilder(100);
final String str = _value;
int ptr = 0;
int len = str.length();
main_loop:
while (ptr < len) {
// first, we'll skip preceding white space, if any
char ch;
do {
ch = str.charAt(ptr++);
if (ptr >= len) {
break main_loop;
}
} while (ch <= ' ');
int bits = b64variant.decodeBase64Char(ch);
if (bits < 0) {
_reportInvalidBase64(b64variant, ch,
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>0);
}
int decodedData = bits;
// then second base64 char; can't get padding yet, nor ws
if (ptr >= len) {
_reportBase64EOF();
}
ch = str.charAt(ptr++);
bits = b64variant.decodeBase64Char(ch);
if (bits < 0) {
_reportInvalidBase64(b64variant, ch, 1);
}
decodedData = (decodedData << 6) | bits;
// third base64 char; can be padding, but not ws
if (ptr >= len) {
// but as per [JACKSON-631] can be end-of-input, iff not using padding
if (!b64variant.usesPadding()) {
// Got 12 bits, only need 8, need to shift
decodedData >>= 4;
builder.append(decodedData);
break;
}
_reportBase64EOF();
}
ch = str.charAt(ptr++);
bits = b64variant.decodeBase64Char(ch);
// First branch: can get padding (-> 1 byte)
if (bits < 0) {
if (bits != Base64Variant.BASE64_VALUE_PADDING) {
_reportInvalidBase64(b64variant, ch, 2);
}
// Ok, must get padding
if (ptr >= len) {
_reportBase64EOF();
}
ch = str.charAt(ptr++);
if (!b64variant.usesPaddingChar(ch)) {
_reportInvalidBase64(b64variant, ch, 3, "expected padding character '"+b64variant.getPaddingChar()+"'");
}
// Got 12 bits, only need 8, need to shift
decodedData >>= 4;
builder.append(decodedData);
continue;
}
// Nope, 2 or 3 bytes
decodedData = (decodedData << 6) | bits;
// fourth and last base64 char; can be padding, but not ws
if (ptr >= len) {
// but as per [JACKSON-631] can be end-of-input, iff not using padding
if (!b64variant.usesPadding()) {
decodedData >>= 2;
builder.appendTwoBytes(decodedData);
break;
}
_reportBase64EOF();
}
ch = str.charAt(ptr++);
bits = b64variant
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>oting
*/
@Override
public String toString()
{
int len = _value.length();
len = len + 2 + (len >> 4);
StringBuilder sb = new StringBuilder(len);
appendQuoted(sb, _value);
return sb.toString();
}
protected static void appendQuoted(StringBuilder sb, String content)
{
sb.append('"');
CharTypes.appendQuoted(sb, content);
sb.append('"');
}
/*
/**********************************************************
/* Helper methods
/**********************************************************
*/
protected void _reportInvalidBase64(Base64Variant b64variant, char ch, int bindex)
throws JsonParseException
{
_reportInvalidBase64(b64variant, ch, bindex, null);
}
/**
* @param bindex Relative index within base64 character unit; between 0
* and 3 (as unit has exactly 4 characters)
*/
protected void _reportInvalidBase64(Base64Variant b64variant, char ch, int bindex, String msg)
throws JsonParseException
{
String base;
if (ch <= ' ') {
base = "Illegal white space character (code 0x"+Integer.toHexString(ch)+") as character #"+(bindex+1)+" of 4-char base64 unit: can only used between units";
} else if (b64variant.usesPaddingChar(ch)) {
base = "Unexpected padding character ('"+b64variant.getPaddingChar()+"') as character #"+(bindex+1)+" of 4-char base64 unit: padding only legal as 3rd or 4th character";
} else if (!Character.isDefined(ch) || Character.isISOControl(ch)) {
// Not sure if we can really get here... ? (most illegal xml chars are caught at lower level)
base = "Illegal character (code 0x"+Integer.toHexString(ch)+") in base64 content";
} else {
base = "Illegal character '"+ch+"' (code 0x"+Integer.toHexString(ch)+") in base64 content";
}
if (msg != null) {
base = base + ": " + msg;
}
throw new JsonParseException(null, base, JsonLocation.NA);
}
protected void _reportBase64EOF() throws JsonParseException {
throw new JsonParseException(null, "Unexpected end-of-String when base64 content");
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS><Object> deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
if (_delegateDeserializer != null) {
return (Collection<Object>) _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(jp, ctxt));
}
if (jp.getCurrentToken() == JsonToken.VALUE_STRING) {
String str = jp.getText();
if (str.length() == 0) {
return (Collection<Object>) _valueInstantiator.createFromString(ctxt, str);
}
}
return deserialize(jp, ctxt, null);
}
@Override
public Collection<Object> deserialize(JsonParser jp, DeserializationContext ctxt, Collection<Object> result0) throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!jp.isExpectedStartArrayToken()) {
return handleNonArray(jp, ctxt, new ArrayBlockingQueue<Object>(1));
}
ArrayList<Object> tmp = new ArrayList<Object>();
JsonDeserializer<Object> valueDes = _valueDeserializer;
JsonToken t;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
try {
while ((t = jp.nextToken()) != JsonToken.END_ARRAY) {
Object value;
if (t == JsonToken.VALUE_NULL) {
value = valueDes.getNullValue(ctxt);
} else if (typeDeser == null) {
value = valueDes.deserialize(jp, ctxt);
} else {
value = valueDes.deserializeWithType(jp, ctxt, typeDeser);
}
tmp.add(value);
}
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, tmp, tmp.size());
}
if (result0 != null) {
result0.addAll(tmp);
return result0;
}
return new ArrayBlockingQueue<Object>(tmp.size(), false, tmp);
}
@Override
public Object deserializeWithType(JsonParser jp, DeserializationContext ctxt, TypeDeserializer typeDeserializer) throws IOException {
// In future could check current token... for now this should be enough:
return typeDeserializer.deserializeTypedFromArray(jp, ctxt);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.node;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.base.ParserMinimalBase;
import com.fasterxml.jackson.databind.JsonNode;
/**
* Facade over {@link JsonNode} that implements {@link JsonParser} to allow
* accessing contents of JSON tree in alternate form (stream of tokens).
* Useful when a streaming source is expected by code, such as data binding
* functionality.
*/
public class TreeTraversingParser extends ParserMinimalBase
{
/*
/**********************************************************
/* Configuration
/**********************************************************
*/
protected ObjectCodec _objectCodec;
/**
* Traversal context within tree
*/
protected NodeCursor _nodeCursor;
/*
/**********************************************************
/* State
/**********************************************************
*/
/**
* Sometimes parser needs to buffer a single look-ahead token; if so,
* it'll be stored here. This is currently used for handling
*/
protected JsonToken _nextToken;
/**
* Flag needed to handle recursion into contents of child
* Array/Object nodes.
*/
protected boolean _startContainer;
/**
* Flag that indicates whether parser is closed or not. Gets
* set when parser is either closed by explicit call
* ({@link #close}) or when end-of-input is reached.
*/
protected boolean _closed;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public TreeTraversingParser(JsonNode n) { this(n, null); }
public TreeTraversingParser(JsonNode n, ObjectCodec codec)
{
super(0);
_objectCodec = codec;
if (n.isArray()) {
_nextToken = JsonToken.START_ARRAY;
_nodeCursor = new NodeCursor.ArrayCursor(n, null);
} else if (n.isObject()) {
_nextToken = JsonToken.START_OBJECT;
_nodeCursor = new NodeCursor.ObjectCursor(n, null);
} else { // value node
_nodeCursor = new NodeCursor.RootCursor(n, null);
}
}
@Override
public void setCodec(ObjectCodec c) {
_objectCodec = c;
}
@Override
public ObjectCodec getCodec() {
return _objectCodec;
}
@Override
public Version version() {
return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION;
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> token accessors
/**********************************************************
*/
@Override
public String getCurrentName() {
return (_nodeCursor == null) ? null : _nodeCursor.getCurrentName();
}
@Override
public void overrideCurrentName(String name)
{
if (_nodeCursor != null) {
_nodeCursor.overrideCurrentName(name);
}
}
@Override
public JsonStreamContext getParsingContext() {
return _nodeCursor;
}
@Override
public JsonLocation getTokenLocation() {
return JsonLocation.NA;
}
@Override
public JsonLocation getCurrentLocation() {
return JsonLocation.NA;
}
/*
/**********************************************************
/* Public API, access to textual content
/**********************************************************
*/
@Override
public String getText()
{
if (_closed) {
return null;
}
// need to separate handling a bit...
switch (_currToken) {
case FIELD_NAME:
return _nodeCursor.getCurrentName();
case VALUE_STRING:
return currentNode().textValue();
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
return String.valueOf(currentNode().numberValue());
case VALUE_EMBEDDED_OBJECT:
JsonNode n = currentNode();
if (n != null && n.isBinary()) {
// this will convert it to base64
return n.asText();
}
default:
return (_currToken == null) ? null : _currToken.asString();
}
}
@Override
public char[] getTextCharacters() throws IOException, JsonParseException {
return getText().toCharArray();
}
@Override
public int getTextLength() throws IOException, JsonParseException {
return getText().length();
}
@Override
public int getTextOffset() throws IOException, JsonParseException {
return 0;
}
@Override
public boolean hasTextCharacters() {
// generally we do not have efficient access as char[], hence:
return false;
}
/*
/**********************************************************
/* Public API, typed non-text access
/**********************************************************
*/
//public byte getByteValue() throws IOException, JsonParseException
@Override
public NumberType getNumberType() throws IOException, JsonParseException {
JsonNode n = currentNumericNode();
return (n == null) ? null : n.numberType();
}
@Override
public BigInteger getBigIntegerValue() throws IOException, JsonParseException
{
return currentNumericNode().bigIntegerValue();
}
@Override
public BigDecimal getDecimalValue() throws IOException, JsonParseException {
return currentNumericNode().decimalValue();
}
@Override
public double
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> getDoubleValue() throws IOException, JsonParseException {
return currentNumericNode().doubleValue();
}
@Override
public float getFloatValue() throws IOException, JsonParseException {
return (float) currentNumericNode().doubleValue();
}
@Override
public long getLongValue() throws IOException, JsonParseException {
return currentNumericNode().longValue();
}
@Override
public int getIntValue() throws IOException, JsonParseException {
return currentNumericNode().intValue();
}
@Override
public Number getNumberValue() throws IOException, JsonParseException {
return currentNumericNode().numberValue();
}
@Override
public Object getEmbeddedObject()
{
if (!_closed) {
JsonNode n = currentNode();
if (n != null) {
if (n.isPojo()) {
return ((POJONode) n).getPojo();
}
if (n.isBinary()) {
return ((BinaryNode) n).binaryValue();
}
}
}
return null;
}
/*
/**********************************************************
/* Public API, typed binary (base64) access
/**********************************************************
*/
@Override
public byte[] getBinaryValue(Base64Variant b64variant)
throws IOException, JsonParseException
{
// Multiple possibilities...
JsonNode n = currentNode();
if (n != null) { // binary node?
byte[] data = n.binaryValue();
// (or TextNode, which can also convert automatically!)
if (data != null) {
return data;
}
// Or maybe byte[] as POJO?
if (n.isPojo()) {
Object ob = ((POJONode) n).getPojo();
if (ob instanceof byte[]) {
return (byte[]) ob;
}
}
}
// otherwise return null to mark we have no binary content
return null;
}
@Override
public int readBinaryValue(Base64Variant b64variant, OutputStream out)
throws IOException, JsonParseException
{
byte[] data = getBinaryValue(b64variant);
if (data != null) {
out.write(data, 0, data.length);
return data.length;
}
return 0;
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected JsonNode currentNode() {
if (_closed || _nodeCursor == null) {
return null;
}
return _nodeCursor.currentNode();
}
protected JsonNode currentNumericNode()
throws JsonParseException
{
JsonNode n = currentNode();
if (n == null || !
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
/**
* Simple general purpose serializer, useful for any
* type for which {@link Object#toString} returns the desired JSON
* value.
*/
@JacksonStdImpl
@SuppressWarnings("serial")
public class ToStringSerializer
extends StdSerializer<Object>
{
/**
* Singleton instance to use.
*/
public final static ToStringSerializer instance = new ToStringSerializer();
/**
*<p>
* Note: usually you should NOT create new instances, but instead use
* {@link #instance} which is stateless and fully thread-safe. However,
* there are cases where constructor is needed; for example,
* when using explicit serializer annotations like
* {@link com.fasterxml.jackson.databind.annotation.JsonSerialize#using}.
*/
public ToStringSerializer() { super(Object.class); }
/**
* Sometimes it may actually make sense to retain actual handled type, so...
*
* @since 2.5
*/
public ToStringSerializer(Class<?> handledType) {
super(handledType, false);
}
@Override
@Deprecated
public boolean isEmpty(Object value) {
return isEmpty(null, value);
}
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
if (value == null) {
return true;
}
String str = value.toString();
return str.isEmpty();
}
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
gen.writeString(value.toString());
}
/* 01-Mar-2011, tatu: We were serializing as "raw" String; but generally that
* is not what we want, since lack of type information would imply real
* String type.
*/
/**
* Default implementation will write type prefix, call regular serialization
* method (since assumption is that value itself does not need JSON
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> _handledType);
if (format != null) {
unwrapSingle = format.getFeature(JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
}
}
if (ser == null) {
ser = _elementSerializer;
}
// #124: May have a content converter
ser = findConvertingContentSerializer(provider, property, ser);
if (ser == null) {
// 30-Sep-2012, tatu: One more thing -- if explicit content type is annotated,
// we can consider it a static case as well.
if (_elementType != null) {
if (_staticTyping && !_elementType.isJavaLangObject()) {
ser = provider.findValueSerializer(_elementType, property);
}
}
} else {
ser = provider.handleSecondaryContextualization(ser, property);
}
return withResolved(property, vts, ser, unwrapSingle);
}
/*
/**********************************************************
/* Accessors
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _elementType;
}
@Override
public JsonSerializer<?> getContentSerializer() {
return _elementSerializer;
}
@Override
public boolean isEmpty(SerializerProvider prov, Object[] value) {
return (value == null) || (value.length == 0);
}
@Override
public boolean hasSingleElement(Object[] value) {
return (value.length == 1);
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(Object[] value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
final int len = value.length;
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(Object[] value, JsonGenerator gen, SerializerProvider provider) throws IOException
{
final int len = value.length;
if (len == 0) {
return;
}
if (_elementSerializer != null) {
serializeContentsUsing(value, gen, provider, _elementSerializer);
return;
}
if (_valueTypeSerializer != null) {
serializeTypedContents(
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>value, gen, provider);
return;
}
int i = 0;
Object elem = null;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(gen);
continue;
}
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
}
serializer.serialize(elem, gen, provider);
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
/* 05-Mar-2009, tatu: But one nasty edge is when we get
* StackOverflow: usually due to infinite loop. But that gets
* hidden within an InvocationTargetException...
*/
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, elem, i);
}
}
public void serializeContentsUsing(Object[] value, JsonGenerator jgen, SerializerProvider provider,
JsonSerializer<Object> ser) throws IOException
{
final int len = value.length;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
Object elem = null;
try {
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, elem, i);
}
}
public void serializeTypedContents(Object[] value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
final int len = value.length;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
Object elem = null;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
elem = value[i];
if (elem == null) {
provider.defaultSerializeNull(jgen);
continue;
}
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializer.serializeWithType(elem, jgen, provider, typeSer);
}
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
if (t instanceof Error) {
throw (Error) t;
}
throw JsonMappingException.wrapWithPath(t, elem, i);
}
}
@SuppressWarnings("deprecation")
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint)
throws JsonMappingException
{
ObjectNode o = createSchemaNode("array", true);
if (typeHint != null) {
JavaType javaType = provider.constructType(typeHint);
if (javaType.isArrayType()) {
Class<?> componentType = ((ArrayType) javaType).getContentType().getRawClass();
// 15-Oct-2010, tatu: We can't serialize plain Object.class; but what should it produce here? Untyped?
if (componentType == Object.class) {
o.set("items", com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode());
} else {
JsonSerializer<Object> ser = provider.findValueSerializer(componentType, _property);
JsonNode schemaNode = (ser instanceof SchemaAware) ?
((SchemaAware) ser).getSchema(provider, null) :
com.fasterxml.jackson.databind.jsonschema.JsonSchema.getDefaultSchemaNode();
o.set("items", schemaNode);
}
}
}
return o;
}
@Override
public void acceptJson
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>v);
}
// was missing from 2.2 and before
@Override
public final NumericNode numberNode(BigInteger v) { return _nodeFactory.numberNode(v); }
@Override
public final NumericNode numberNode(float v) { return _nodeFactory.numberNode(v); }
@Override
public final NumericNode numberNode(double v) { return _nodeFactory.numberNode(v); }
@Override
public final NumericNode numberNode(BigDecimal v) { return (_nodeFactory.numberNode(v)); }
// // Wrapper types, missing from 2.2 and before
@Override
public final ValueNode numberNode(Byte v) { return _nodeFactory.numberNode(v); }
@Override
public final ValueNode numberNode(Short v) { return _nodeFactory.numberNode(v); }
@Override
public final ValueNode numberNode(Integer v) { return _nodeFactory.numberNode(v); }
@Override
public final ValueNode numberNode(Long v) { return _nodeFactory.numberNode(v); }
@Override
public final ValueNode numberNode(Float v) { return _nodeFactory.numberNode(v); }
@Override
public final ValueNode numberNode(Double v) { return _nodeFactory.numberNode(v); }
@Override
public final TextNode textNode(String text) { return _nodeFactory.textNode(text); }
@Override
public final BinaryNode binaryNode(byte[] data) { return _nodeFactory.binaryNode(data); }
@Override
public final BinaryNode binaryNode(byte[] data, int offset, int length) { return _nodeFactory.binaryNode(data, offset, length); }
@Override
public final ValueNode pojoNode(Object pojo) { return _nodeFactory.pojoNode(pojo); }
@Override
public final ValueNode rawValueNode(RawValue value) { return _nodeFactory.rawValueNode(value); }
/*
/**********************************************************
/* Common mutators
/**********************************************************
*/
/**
* Method for removing all children container has (if any)
*
* @return Container node itself (to allow method call chaining)
*/
public abstract T removeAll();
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>;
if (ptr >= values.length) {
values = buffer.appendCompletedChunk(values);
ptr = 0;
}
values[ptr++] = value;
} while (jp.nextToken() != JsonToken.END_ARRAY);
// let's create full array then
ArrayList<Object> result = new ArrayList<Object>(totalSize);
buffer.completeAndClearBuffer(values, ptr, result);
return result;
}
/**
* Method called to map a JSON Object into a Java value.
*/
protected Object mapObject(JsonParser p, DeserializationContext ctxt) throws IOException
{
String key1;
JsonToken t = p.getCurrentToken();
if (t == JsonToken.START_OBJECT) {
key1 = p.nextFieldName();
} else if (t == JsonToken.FIELD_NAME) {
key1 = p.getCurrentName();
} else {
if (t != JsonToken.END_OBJECT) {
throw ctxt.mappingException(handledType(), p.getCurrentToken());
}
key1 = null;
}
if (key1 == null) {
// empty map might work; but caller may want to modify... so better just give small modifiable
return new LinkedHashMap<String,Object>(2);
}
// minor optimization; let's handle 1 and 2 entry cases separately
// 24-Mar-2015, tatu: Ideally, could use one of 'nextXxx()' methods, but for
// that we'd need new method(s) in JsonDeserializer. So not quite yet.
p.nextToken();
Object value1 = deserialize(p, ctxt);
String key2 = p.nextFieldName();
if (key2 == null) { // has to be END_OBJECT, then
// single entry; but we want modifiable
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(2);
result.put(key1, value1);
return result;
}
p.nextToken();
Object value2 = deserialize(p, ctxt);
String key = p.nextFieldName();
if (key == null) {
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(4);
result.put(key1, value1);
result.put(key2, value2);
return result;
}
// And then the general case; default map size is 16
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
result.put(key1, value1);
result.put(key
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>2, value2);
do {
p.nextToken();
result.put(key, deserialize(p, ctxt));
} while ((key = p.nextFieldName()) != null);
return result;
}
/**
* Method called to map a JSON Array into a Java Object array (Object[]).
*/
protected Object[] mapArrayToArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
// Minor optimization to handle small lists (default size for ArrayList is 10)
if (jp.nextToken() == JsonToken.END_ARRAY) {
return NO_OBJECTS;
}
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
int ptr = 0;
do {
Object value = deserialize(jp, ctxt);
if (ptr >= values.length) {
values = buffer.appendCompletedChunk(values);
ptr = 0;
}
values[ptr++] = value;
} while (jp.nextToken() != JsonToken.END_ARRAY);
return buffer.completeAndClearBuffer(values, ptr);
}
/*
/**********************************************************
/* Separate "vanilla" implementation for common case of
/* no custom deserializer overrides
/**********************************************************
*/
@JacksonStdImpl
public static class Vanilla
extends StdDeserializer<Object>
{
private static final long serialVersionUID = 1L;
public final static Vanilla std = new Vanilla();
public Vanilla() { super(Object.class); }
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_START_OBJECT:
{
JsonToken t = p.nextToken();
if (t == JsonToken.END_OBJECT) {
return new LinkedHashMap<String,Object>(2);
}
}
case JsonTokenId.ID_FIELD_NAME:
return mapObject(p, ctxt);
case JsonTokenId.ID_START_ARRAY:
{
JsonToken t = p.nextToken();
if (t == JsonToken.END_ARRAY) { // and empty one too
if (ctxt.isEnabled(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)) {
return NO_OBJECTS;
}
return new ArrayList<Object>(2);
}
}
if (ctxt.isEnabled(DeserializationFeature.USE_JAVA_ARRAY_FOR_JSON_ARRAY)) {
return mapArrayToArray(p, ctxt);
}
return mapArray(p, ctxt);
case
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>EMBEDDED_OBJECT:
return jp.getEmbeddedObject();
case JsonTokenId.ID_NULL: // should not get this far really but...
return null;
default:
throw ctxt.mappingException(Object.class);
}
}
protected Object mapArray(JsonParser jp, DeserializationContext ctxt) throws IOException
{
Object value = deserialize(jp, ctxt);
if (jp.nextToken() == JsonToken.END_ARRAY) {
ArrayList<Object> l = new ArrayList<Object>(2);
l.add(value);
return l;
}
Object value2 = deserialize(jp, ctxt);
if (jp.nextToken() == JsonToken.END_ARRAY) {
ArrayList<Object> l = new ArrayList<Object>(2);
l.add(value);
l.add(value2);
return l;
}
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
int ptr = 0;
values[ptr++] = value;
values[ptr++] = value2;
int totalSize = ptr;
do {
value = deserialize(jp, ctxt);
++totalSize;
if (ptr >= values.length) {
values = buffer.appendCompletedChunk(values);
ptr = 0;
}
values[ptr++] = value;
} while (jp.nextToken() != JsonToken.END_ARRAY);
// let's create full array then
ArrayList<Object> result = new ArrayList<Object>(totalSize);
buffer.completeAndClearBuffer(values, ptr, result);
return result;
}
/**
* Method called to map a JSON Object into a Java value.
*/
protected Object mapObject(JsonParser p, DeserializationContext ctxt) throws IOException
{
// will point to FIELD_NAME at this point, guaranteed
String key1 = p.getText();
p.nextToken();
Object value1 = deserialize(p, ctxt);
String key2 = p.nextFieldName();
if (key2 == null) { // single entry; but we want modifiable
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(2);
result.put(key1, value1);
return result;
}
p.nextToken();
Object value2 = deserialize(p, ctxt);
String key = p.nextFieldName();
if (key == null) {
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>(4);
result.put(key1, value1);
result.put(key2,
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> value2);
return result;
}
// And then the general case; default map size is 16
LinkedHashMap<String, Object> result = new LinkedHashMap<String, Object>();
result.put(key1, value1);
result.put(key2, value2);
do {
p.nextToken();
result.put(key, deserialize(p, ctxt));
} while ((key = p.nextFieldName()) != null);
return result;
}
/**
* Method called to map a JSON Array into a Java Object array (Object[]).
*/
protected Object[] mapArrayToArray(JsonParser jp, DeserializationContext ctxt) throws IOException {
ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] values = buffer.resetAndStart();
int ptr = 0;
do {
Object value = deserialize(jp, ctxt);
if (ptr >= values.length) {
values = buffer.appendCompletedChunk(values);
ptr = 0;
}
values[ptr++] = value;
} while (jp.nextToken() != JsonToken.END_ARRAY);
return buffer.completeAndClearBuffer(values, ptr);
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>) {
return this;
}
/*
/**********************************************************
/* Post-processing
/**********************************************************
*/
@Override
public JsonSerializer<?> createContextual(SerializerProvider provider,
BeanProperty property)
throws JsonMappingException
{
/* 29-Sep-2012, tatu: Actually, we need to do much more contextual
* checking here since we finally know for sure the property,
* and it may have overrides
*/
JsonSerializer<?> ser = null;
// First: if we have a property, may have property-annotation overrides
if (property != null) {
final AnnotationIntrospector ai = provider.getAnnotationIntrospector();
AnnotatedMember m = property.getMember();
if (m != null) {
Object serDef = ai.findContentSerializer(m);
if (serDef != null) {
ser = provider.serializerInstance(m, serDef);
}
}
}
// but since formats have both property overrides and global per-type defaults,
// need to do that separately
Boolean unwrapSingle = findFormatFeature(provider, property, String[].class,
JsonFormat.Feature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED);
if (ser == null) {
ser = _elementSerializer;
}
// May have a content converter
ser = findConvertingContentSerializer(provider, property, ser);
if (ser == null) {
ser = provider.findValueSerializer(String.class, property);
} else {
ser = provider.handleSecondaryContextualization(ser, property);
}
// Optimization: default serializer just writes String, so we can avoid a call:
if (isDefaultSerializer(ser)) {
ser = null;
}
// note: will never have TypeSerializer, because Strings are "natural" type
if ((ser == _elementSerializer) && (unwrapSingle == _unwrapSingle)) {
return this;
}
return new StringArraySerializer(this, property, ser, unwrapSingle);
}
/*
/**********************************************************
/* Simple accessors
/**********************************************************
*/
@Override
public JavaType getContentType() {
return VALUE_TYPE;
}
@Override
public JsonSerializer<?> getContentSerializer() {
return _elementSerializer;
}
@Override
public boolean isEmpty(SerializerProvider prov, String[] value) {
return (value == null) || (value.length == 0);
}
@Override
public boolean hasSingleElement(String[] value) {
return (value.length == 1);
}
/*
/********************************************************
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>**
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(String[] value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final int len = value.length;
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, gen, provider);
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(String[] value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
final int len = value.length;
if (len == 0) {
return;
}
if (_elementSerializer != null) {
serializeContentsSlow(value, gen, provider, _elementSerializer);
return;
}
for (int i = 0; i < len; ++i) {
String str = value[i];
if (str == null) {
gen.writeNull();
} else {
gen.writeString(value[i]);
}
}
}
private void serializeContentsSlow(String[] value, JsonGenerator gen, SerializerProvider provider, JsonSerializer<Object> ser)
throws IOException
{
for (int i = 0, len = value.length; i < len; ++i) {
String str = value[i];
if (str == null) {
provider.defaultSerializeNull(gen);
} else {
ser.serialize(value[i], gen, provider);
}
}
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("array", true).set("items", createSchemaNode("string"));
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
visitArrayFormat(visitor, typeHint, JsonFormatTypes.STRING);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>pre>
* which would make all member fields serializable without further annotations,
* instead of just public fields (default setting).
*
* @param forMethod Type of property descriptor affected (field, getter/isGetter,
* setter, creator)
* @param visibility Minimum visibility to require for the property descriptors of type
*
* @return Modified mapper instance (that is, "this"), to allow chaining
* of configuration calls
*/
public ObjectMapper setVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility)
{
_deserializationConfig = _deserializationConfig.withVisibility(forMethod, visibility);
_serializationConfig = _serializationConfig.withVisibility(forMethod, visibility);
return this;
}
/**
* Method for accessing subtype resolver in use.
*/
public SubtypeResolver getSubtypeResolver() {
return _subtypeResolver;
}
/**
* Method for setting custom subtype resolver to use.
*/
public ObjectMapper setSubtypeResolver(SubtypeResolver str) {
_subtypeResolver = str;
_deserializationConfig = _deserializationConfig.with(str);
_serializationConfig = _serializationConfig.with(str);
return this;
}
/**
* Method for setting {@link AnnotationIntrospector} used by this
* mapper instance for both serialization and deserialization.
* Note that doing this will replace the current introspector, which
* may lead to unavailability of core Jackson annotations.
* If you want to combine handling of multiple introspectors,
* have a look at {@link com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair}.
*
* @see com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair
*/
public ObjectMapper setAnnotationIntrospector(AnnotationIntrospector ai) {
_serializationConfig = _serializationConfig.with(ai);
_deserializationConfig = _deserializationConfig.with(ai);
return this;
}
/**
* Method for changing {@link AnnotationIntrospector} instances used
* by this mapper instance for serialization and deserialization,
* specifying them separately so that different introspection can be
* used for different aspects
*
* @since 2.1
*
* @param serializerAI {@link AnnotationIntrospector} to use for configuring
* serialization
* @param deserializerAI {@link AnnotationIntrospector} to use for configuring
* deserialization
*
* @see com.fasterxml.jackson.databind.introspect.AnnotationIntrospectorPair
*/
public ObjectMapper setAnnotationIntrospectors(AnnotationInt
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>n.isEmpty()) {
continue;
}
if (expl == null) {
expl = new HashMap<String,String>();
}
expl.put(f.getName(), n);
}
// and then stitch them together if and as necessary
if (expl != null) {
for (int i = 0, end = enumValues.length; i < end; ++i) {
String defName = enumValues[i].name();
String explValue = expl.get(defName);
if (explValue != null) {
names[i] = explValue;
}
}
}
return names;
}
/*
/**********************************************************
/* General class annotations
/**********************************************************
*/
@Override
public PropertyName findRootName(AnnotatedClass ac)
{
JsonRootName ann = _findAnnotation(ac, JsonRootName.class);
if (ann == null) {
return null;
}
String ns = ann.namespace();
if (ns != null && ns.length() == 0) {
ns = null;
}
return PropertyName.construct(ann.value(), ns);
}
@Override
@Deprecated // since 2.6, remove from 2.7 or later
public String[] findPropertiesToIgnore(Annotated ac) {
JsonIgnoreProperties ignore = _findAnnotation(ac, JsonIgnoreProperties.class);
return (ignore == null) ? null : ignore.value();
}
@Override // since 2.6
public String[] findPropertiesToIgnore(Annotated ac, boolean forSerialization) {
JsonIgnoreProperties ignore = _findAnnotation(ac, JsonIgnoreProperties.class);
if (ignore == null) {
return null;
}
// 13-May-2015, tatu: As per [databind#95], allow read-only/write-only props
if (forSerialization) {
if (ignore.allowGetters()) {
return null;
}
} else {
if (ignore.allowSetters()) {
return null;
}
}
return ignore.value();
}
@Override
public Boolean findIgnoreUnknownProperties(AnnotatedClass ac) {
JsonIgnoreProperties ignore = _findAnnotation(ac, JsonIgnoreProperties.class);
return (ignore == null) ? null : ignore.ignoreUnknown();
}
@Override
public Boolean isIgnorableType(AnnotatedClass ac) {
JsonIgnoreType ignore = _findAnnotation(ac, JsonIgnoreType.class);
return (ignore == null) ? null : ignore.
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>value();
}
@Override
public Object findFilterId(Annotated a) {
JsonFilter ann = _findAnnotation(a, JsonFilter.class);
if (ann != null) {
String id = ann.value();
// Empty String is same as not having annotation, to allow overrides
if (id.length() > 0) {
return id;
}
}
return null;
}
@Override
public Object findNamingStrategy(AnnotatedClass ac)
{
JsonNaming ann = _findAnnotation(ac, JsonNaming.class);
return (ann == null) ? null : ann.value();
}
@Override
public String findClassDescription(AnnotatedClass ac) {
JsonClassDescription ann = _findAnnotation(ac, JsonClassDescription.class);
return (ann == null) ? null : ann.value();
}
/*
/**********************************************************
/* Property auto-detection
/**********************************************************
*/
@Override
public VisibilityChecker<?> findAutoDetectVisibility(AnnotatedClass ac,
VisibilityChecker<?> checker)
{
JsonAutoDetect ann = _findAnnotation(ac, JsonAutoDetect.class);
return (ann == null) ? checker : checker.with(ann);
}
/*
/**********************************************************
/* General member (field, method/constructor) annotations
/**********************************************************
*/
@Override
public String findImplicitPropertyName(AnnotatedMember m) {
PropertyName n = _findConstructorName(m);
return (n == null) ? null : n.getSimpleName();
}
@Override
public boolean hasIgnoreMarker(AnnotatedMember m) {
return _isIgnorable(m);
}
@Override
public Boolean hasRequiredMarker(AnnotatedMember m)
{
JsonProperty ann = _findAnnotation(m, JsonProperty.class);
if (ann != null) {
return ann.required();
}
return null;
}
@Override
public JsonProperty.Access findPropertyAccess(Annotated m) {
JsonProperty ann = _findAnnotation(m, JsonProperty.class);
if (ann != null) {
return ann.access();
}
return null;
}
@Override
public String findPropertyDescription(Annotated ann) {
JsonPropertyDescription desc = _findAnnotation(ann, JsonPropertyDescription.class);
return (desc == null) ? null : desc.value();
}
@Override
public Integer findPropertyIndex(Annotated ann) {
JsonProperty prop = _findAnnotation(ann, JsonProperty.class);
if (prop != null) {
int ix = prop.index();
if (
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>ix != JsonProperty.INDEX_UNKNOWN) {
return Integer.valueOf(ix);
}
}
return null;
}
@Override
public String findPropertyDefaultValue(Annotated ann) {
JsonProperty prop = _findAnnotation(ann, JsonProperty.class);
if (prop == null) {
return null;
}
String str = prop.defaultValue();
// Since annotations do not allow nulls, need to assume empty means "none"
return str.isEmpty() ? null : str;
}
@Override
public JsonFormat.Value findFormat(Annotated ann) {
JsonFormat f = _findAnnotation(ann, JsonFormat.class);
return (f == null) ? null : new JsonFormat.Value(f);
}
@Override
public ReferenceProperty findReferenceType(AnnotatedMember member)
{
JsonManagedReference ref1 = _findAnnotation(member, JsonManagedReference.class);
if (ref1 != null) {
return AnnotationIntrospector.ReferenceProperty.managed(ref1.value());
}
JsonBackReference ref2 = _findAnnotation(member, JsonBackReference.class);
if (ref2 != null) {
return AnnotationIntrospector.ReferenceProperty.back(ref2.value());
}
return null;
}
@Override
public NameTransformer findUnwrappingNameTransformer(AnnotatedMember member)
{
JsonUnwrapped ann = _findAnnotation(member, JsonUnwrapped.class);
// if not enabled, just means annotation is not enabled; not necessarily
// that unwrapping should not be done (relevant when using chained introspectors)
if (ann == null || !ann.enabled()) {
return null;
}
String prefix = ann.prefix();
String suffix = ann.suffix();
return NameTransformer.simpleTransformer(prefix, suffix);
}
@Override
public Object findInjectableValueId(AnnotatedMember m)
{
JacksonInject ann = _findAnnotation(m, JacksonInject.class);
if (ann == null) {
return null;
}
/* Empty String means that we should use name of declared
* value class.
*/
String id = ann.value();
if (id.length() == 0) {
// slight complication; for setters, type
if (!(m instanceof AnnotatedMethod)) {
return m.getRawType().getName();
}
AnnotatedMethod am = (AnnotatedMethod) m;
if (am.getParameterCount() == 0) {
return m.getRawType().getName();
}
return am.getRawParameterType(0).
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
}
return _findTypeResolver(config, am, containerType);
}
@Override
public List<NamedType> findSubtypes(Annotated a)
{
JsonSubTypes t = _findAnnotation(a, JsonSubTypes.class);
if (t == null) return null;
JsonSubTypes.Type[] types = t.value();
ArrayList<NamedType> result = new ArrayList<NamedType>(types.length);
for (JsonSubTypes.Type type : types) {
result.add(new NamedType(type.value(), type.name()));
}
return result;
}
@Override
public String findTypeName(AnnotatedClass ac)
{
JsonTypeName tn = _findAnnotation(ac, JsonTypeName.class);
return (tn == null) ? null : tn.value();
}
@Override
public Boolean isTypeId(AnnotatedMember member) {
return _hasAnnotation(member, JsonTypeId.class);
}
/*
/**********************************************************
/* Annotations for Object Id handling
/**********************************************************
*/
@Override
public ObjectIdInfo findObjectIdInfo(Annotated ann) {
JsonIdentityInfo info = _findAnnotation(ann, JsonIdentityInfo.class);
if (info == null || info.generator() == ObjectIdGenerators.None.class) {
return null;
}
// In future may need to allow passing namespace?
PropertyName name = PropertyName.construct(info.property());
return new ObjectIdInfo(name, info.scope(), info.generator(), info.resolver());
}
@Override
public ObjectIdInfo findObjectReferenceInfo(Annotated ann, ObjectIdInfo objectIdInfo) {
JsonIdentityReference ref = _findAnnotation(ann, JsonIdentityReference.class);
if (ref != null) {
objectIdInfo = objectIdInfo.withAlwaysAsId(ref.alwaysAsId());
}
return objectIdInfo;
}
/*
/**********************************************************
/* Serialization: general annotations
/**********************************************************
*/
@Override
public Object findSerializer(Annotated a)
{
JsonSerialize ann = _findAnnotation(a, JsonSerialize.class);
if (ann != null) {
@SuppressWarnings("rawtypes")
Class<? extends JsonSerializer> serClass = ann.using();
if (serClass != JsonSerializer.None.class) {
return serClass;
}
}
/* 18-Oct-2010, tatu: [JACKSON-351] @JsonRawValue handled just here, for now;
* if we need to get raw indicator from other sources need to add
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> return (ann == null) ? null : _classIfExplicit(ann.contentAs());
}
@Override
public JsonSerialize.Typing findSerializationTyping(Annotated a)
{
JsonSerialize ann = _findAnnotation(a, JsonSerialize.class);
return (ann == null) ? null : ann.typing();
}
@Override
public Object findSerializationConverter(Annotated a) {
JsonSerialize ann = _findAnnotation(a, JsonSerialize.class);
return (ann == null) ? null : _classIfExplicit(ann.converter(), Converter.None.class);
}
@Override
public Object findSerializationContentConverter(AnnotatedMember a) {
JsonSerialize ann = _findAnnotation(a, JsonSerialize.class);
return (ann == null) ? null : _classIfExplicit(ann.contentConverter(), Converter.None.class);
}
/*
/**********************************************************
/* Serialization: class annotations
/**********************************************************
*/
@Override
public String[] findSerializationPropertyOrder(AnnotatedClass ac) {
JsonPropertyOrder order = _findAnnotation(ac, JsonPropertyOrder.class);
return (order == null) ? null : order.value();
}
@Override
public Boolean findSerializationSortAlphabetically(Annotated ann) {
return _findSortAlpha(ann);
}
private final Boolean _findSortAlpha(Annotated ann) {
JsonPropertyOrder order = _findAnnotation(ann, JsonPropertyOrder.class);
/* 23-Jun-2015, tatu: as per [databind#840], let's only consider
* `true` to have any significance.
*/
if ((order != null) && order.alphabetic()) {
return Boolean.TRUE;
}
return null;
}
@Override
public void findAndAddVirtualProperties(MapperConfig<?> config, AnnotatedClass ac,
List<BeanPropertyWriter> properties) {
JsonAppend ann = _findAnnotation(ac, JsonAppend.class);
if (ann == null) {
return;
}
final boolean prepend = ann.prepend();
JavaType propType = null;
// First: any attribute-backed properties?
JsonAppend.Attr[] attrs = ann.attrs();
for (int i = 0, len = attrs.length; i < len; ++i) {
if (propType == null) {
propType = config.constructType(Object.class);
}
BeanPropertyWriter bpw = _constructVirtualProperty(attrs[i],
config, ac, propType);
if (prepend) {
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> properties.add(i, bpw);
} else {
properties.add(bpw);
}
}
// Then: general-purpose virtual properties?
JsonAppend.Prop[] props = ann.props();
for (int i = 0, len = props.length; i < len; ++i) {
BeanPropertyWriter bpw = _constructVirtualProperty(props[i],
config, ac);
if (prepend) {
properties.add(i, bpw);
} else {
properties.add(bpw);
}
}
}
protected BeanPropertyWriter _constructVirtualProperty(JsonAppend.Attr attr,
MapperConfig<?> config, AnnotatedClass ac, JavaType type)
{
PropertyMetadata metadata = attr.required() ?
PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL;
// could add Index, Description in future, if those matter
String attrName = attr.value();
// allow explicit renaming; if none, default to attribute name
PropertyName propName = _propertyName(attr.propName(), attr.propNamespace());
if (!propName.hasSimpleName()) {
propName = PropertyName.construct(attrName);
}
// now, then, we need a placeholder for member (no real Field/Method):
AnnotatedMember member = new VirtualAnnotatedMember(ac, ac.getRawType(),
attrName, type.getRawClass());
// and with that and property definition
SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(config,
member, propName, metadata, attr.include());
// can construct the property writer
return AttributePropertyWriter.construct(attrName, propDef,
ac.getAnnotations(), type);
}
protected BeanPropertyWriter _constructVirtualProperty(JsonAppend.Prop prop,
MapperConfig<?> config, AnnotatedClass ac)
{
PropertyMetadata metadata = prop.required() ?
PropertyMetadata.STD_REQUIRED : PropertyMetadata.STD_OPTIONAL;
PropertyName propName = _propertyName(prop.name(), prop.namespace());
JavaType type = config.constructType(prop.type());
// now, then, we need a placeholder for member (no real Field/Method):
AnnotatedMember member = new VirtualAnnotatedMember(ac, ac.getRawType(),
propName.getSimpleName(), type.getRawClass());
// and with that and property definition
SimpleBeanPropertyDefinition propDef = SimpleBeanPropertyDefinition.construct(config,
member, propName, metadata, prop.include());
Class<?> implClass = prop.value();
HandlerInstantiator hi = config.get
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
return StdTypeResolverBuilder.noTypeInfoBuilder();
}
/*
/**********************************************************
/* Helper classes
/**********************************************************
*/
/**
* To support Java7-incomplete platforms, we will offer support for JDK 7
* annotations through this class, loaded dynamically; if loading fails,
* support will be missing.
*/
private static class Java7Support
{
@SuppressWarnings("unused") // compiler warns, just needed side-effects
private final Class<?> _bogus;
@SuppressWarnings("unused") // compiler warns; called via Reflection
public Java7Support() {
// Trigger loading of annotations that only JDK 7 has...
Class<?> cls = Transient.class;
cls = ConstructorProperties.class;
_bogus = cls;
}
public Boolean findTransient(Annotated a) {
Transient t = a.getAnnotation(Transient.class);
if (t != null) {
return t.value();
}
return null;
}
public Boolean hasCreatorAnnotation(Annotated a) {
ConstructorProperties props = a.getAnnotation(ConstructorProperties.class);
// 08-Nov-2015, tatu: One possible check would be to ensure there is at least
// one name iff constructor has arguments. But seems unnecessary for now.
if (props != null) {
return Boolean.TRUE;
}
return null;
}
public PropertyName findConstructorName(AnnotatedParameter p)
{
AnnotatedWithParams ctor = p.getOwner();
if (ctor != null) {
ConstructorProperties props = ctor.getAnnotation(ConstructorProperties.class);
if (props != null) {
String[] names = props.value();
int ix = p.getIndex();
if (ix < names.length) {
return PropertyName.construct(names[ix]);
}
}
}
return null;
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> null
* when deserializing root values
*
* @since 2.5
*/
public JsonDeserializer<?> handleSecondaryContextualization(JsonDeserializer<?> deser,
BeanProperty prop, JavaType type)
throws JsonMappingException
{
if (deser instanceof ContextualDeserializer) {
_currentType = new LinkedNode<JavaType>(type, _currentType);
try {
deser = ((ContextualDeserializer) deser).createContextual(this, prop);
} finally {
_currentType = _currentType.next();
}
}
return deser;
}
@Deprecated // since 2.5; remove from 2.7
public JsonDeserializer<?> handlePrimaryContextualization(JsonDeserializer<?> deser, BeanProperty prop) throws JsonMappingException {
return handlePrimaryContextualization(deser, prop, TypeFactory.unknownType());
}
@Deprecated // since 2.5; remove from 2.7
public JsonDeserializer<?> handleSecondaryContextualization(JsonDeserializer<?> deser, BeanProperty prop) throws JsonMappingException {
if (deser instanceof ContextualDeserializer) {
deser = ((ContextualDeserializer) deser).createContextual(this, prop);
}
return deser;
}
/*
/**********************************************************
/* Parsing methods that may use reusable/-cyclable objects
/**********************************************************
*/
/**
* Convenience method for parsing a Date from given String, using
* currently configured date format (accessed using
* {@link DeserializationConfig#getDateFormat()}).
*<p>
* Implementation will handle thread-safety issues related to
* date formats such that first time this method is called,
* date format is cloned, and cloned instance will be retained
* for use during this deserialization round.
*/
public Date parseDate(String dateStr) throws IllegalArgumentException
{
try {
DateFormat df = getDateFormat();
return df.parse(dateStr);
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(
"Failed to parse Date value '%s': %s", dateStr, e.getMessage()));
}
}
/**
* Convenience method for constructing Calendar instance set
* to specified time, to be modified and used by caller.
*/
public Calendar constructCalendar(Date d) {
// 08-Jan-2008, tatu: not optimal, but should work for the most part; let's revise as needed.
Calendar c = Calendar.getInstance(getTimeZone());
c.setTime(d);
return c;
}
/*
/**********************************************************
/* Convenience methods for
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> configured problem handler that was able to handle the
* problem
*/
public boolean handleUnknownProperty(JsonParser p, JsonDeserializer<?> deser,
Object instanceOrClass, String propName)
throws IOException, JsonProcessingException
{
LinkedNode<DeserializationProblemHandler> h = _config.getProblemHandlers();
if (h != null) {
while (h != null) {
// Can bail out if it's handled
if (h.value().handleUnknownProperty(this, p, deser, instanceOrClass, propName)) {
return true;
}
h = h.next();
}
}
return false;
}
/**
* Helper method for reporting a problem with unhandled unknown exception
*
* @param instanceOrClass Either value being populated (if one has been
* instantiated), or Class that indicates type that would be (or
* have been) instantiated
* @param deser Deserializer that had the problem, if called by deserializer
* (or on behalf of one)
*/
public void reportUnknownProperty(Object instanceOrClass, String fieldName,
JsonDeserializer<?> deser)
throws JsonMappingException
{
if (!isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
return;
}
// Do we know properties that are expected instead?
Collection<Object> propIds = (deser == null) ? null : deser.getKnownPropertyNames();
throw UnrecognizedPropertyException.from(_parser,
instanceOrClass, fieldName, propIds);
}
/**
* @since 2.8
*/
public JsonMappingException reportMappingException(String msg, Object... msgArgs)
throws JsonMappingException
{
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
throw mappingException(msg);
}
/**
* @since 2.8
*/
public JsonMappingException reportInstantiationException(Class<?> instClass, Throwable t)
throws JsonMappingException
{
throw instantiationException(instClass, t);
}
/**
* @since 2.8
*/
public JsonMappingException reportInstantiationException(Class<?> instClass,
String msg, Object... msgArgs)
throws JsonMappingException
{
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
throw instantiationException(instClass, msg);
}
/**
* @since 2.8
*/
public <T> T reportWeirdStringException(String value, Class<?> instClass,
String msg
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>, Object... msgArgs)
throws JsonMappingException
{
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
throw weirdStringException(value, instClass, msg);
}
/**
* @since 2.8
*/
public <T> T reportWeirdNumberException(Number value, Class<?> instClass,
String msg, Object... msgArgs)
throws JsonMappingException
{
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
throw weirdNumberException(value, instClass, msg);
}
/**
* @since 2.8
*/
public <T> T reportWeirdKeyException(Class<?> keyClass, String keyValue,
String msg, Object... msgArgs)
throws JsonMappingException
{
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
throw weirdKeyException(keyClass, keyValue, msg);
}
/**
* @since 2.8
*/
public <T> T reportWrongTokenException(JsonParser p,
JsonToken expToken, String msg, Object... msgArgs)
throws JsonMappingException
{
if (msgArgs.length > 0) {
msg = String.format(msg, msgArgs);
}
throw wrongTokenException(p, expToken, msg);
}
/**
* @since 2.8
*/
public <T> T reportUnknownTypeException(JavaType type, String id,
String extraDesc) throws JsonMappingException
{
throw unknownTypeException(type, id, extraDesc);
}
/**
* @since 2.8
*/
public <T> T reportEndOfInputException(Class<?> instClass) throws JsonMappingException {
throw endOfInputException(instClass);
}
/*
/**********************************************************
/* Methods for constructing exceptions
/**********************************************************
*/
/**
* Helper method for constructing generic mapping exception for specified type
*/
public JsonMappingException mappingException(Class<?> targetClass) {
return mappingException(targetClass, _parser.getCurrentToken());
}
public JsonMappingException mappingException(Class<?> targetClass, JsonToken token) {
String tokenDesc = (token == null) ? "<end of input>" : String.format("%s token", token);
return JsonMappingException.from(_parser,
String.format("Can not deserialize instance of %s out of %s",
_calcName(target
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> df;
}
protected String determineClassName(Object instance) {
return ClassUtil.getClassDescription(instance);
}
/*
/**********************************************************
/* Other internal methods
/**********************************************************
*/
protected String _calcName(Class<?> cls) {
if (cls.isArray()) {
return _calcName(cls.getComponentType())+"[]";
}
return cls.getName();
}
protected String _valueDesc() {
try {
return _desc(_parser.getText());
} catch (Exception e) {
return "[N/A]";
}
}
protected String _desc(String desc) {
if (desc == null) {
return "[N/A]";
}
// !!! should we quote it? (in case there are control chars, linefeeds)
if (desc.length() > MAX_ERROR_STR_LEN) {
desc = desc.substring(0, MAX_ERROR_STR_LEN) + "]...[" + desc.substring(desc.length() - MAX_ERROR_STR_LEN);
}
return desc;
}
// @since 2.7
protected String _quotedString(String desc) {
if (desc == null) {
return "[N/A]";
}
// !!! should we quote it? (in case there are control chars, linefeeds)
if (desc.length() > MAX_ERROR_STR_LEN) {
return String.format("\"%s]...[%s\"",
desc.substring(0, MAX_ERROR_STR_LEN),
desc.substring(desc.length() - MAX_ERROR_STR_LEN));
}
return "\"" + desc + "\"";
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.deser.std;
import java.io.IOException;
import java.util.Arrays;
import java.util.UUID;
import com.fasterxml.jackson.core.Base64Variants;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.exc.InvalidFormatException;
public class UUIDDeserializer extends FromStringDeserializer<UUID>
{
private static final long serialVersionUID = 1L;
final static int[] HEX_DIGITS = new int[127];
static {
Arrays.fill(HEX_DIGITS, -1);
for (int i = 0; i < 10; ++i) { HEX_DIGITS['0' + i] = i; }
for (int i = 0; i < 6; ++i) {
HEX_DIGITS['a' + i] = 10 + i;
HEX_DIGITS['A' + i] = 10 + i;
}
}
public UUIDDeserializer() { super(UUID.class); }
@Override
protected UUID _deserialize(String id, DeserializationContext ctxt) throws IOException
{
// Adapted from java-uuid-generator (https://github.com/cowtowncoder/java-uuid-generator)
// which is 5x faster than UUID.fromString(value), as oper "ManualReadPerfWithUUID"
if (id.length() != 36) {
/* 14-Sep-2013, tatu: One trick we do allow, Base64-encoding, since we know
* length it must have...
*/
if (id.length() == 24) {
byte[] stuff = Base64Variants.getDefaultVariant().decode(id);
return _fromBytes(stuff, ctxt);
}
_badFormat(id, ctxt);
}
// verify hyphens first:
if ((id.charAt(8) != '-') || (id.charAt(13) != '-')
|| (id.charAt(18) != '-') || (id.charAt(23) != '-')) {
_badFormat(id, ctxt);
}
long l1 = intFromChars(id, 0, ctxt);
l1 <<= 32;
long l2 = ((long) shortFromChars(id, 9, ctxt)) << 16;
l2 |= shortFromChars(id, 14,
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> ctxt);
long hi = l1 + l2;
int i1 = (shortFromChars(id, 19, ctxt) << 16) | shortFromChars(id, 24, ctxt);
l1 = i1;
l1 <<= 32;
l2 = intFromChars(id, 28, ctxt);
l2 = (l2 << 32) >>> 32; // sign removal, Java-style. Ugh.
long lo = l1 | l2;
return new UUID(hi, lo);
}
@Override
protected UUID _deserializeEmbedded(Object ob, DeserializationContext ctxt) throws IOException
{
if (ob instanceof byte[]) {
return _fromBytes((byte[]) ob, ctxt);
}
super._deserializeEmbedded(ob, ctxt);
return null; // never gets here
}
private void _badFormat(String uuidStr, DeserializationContext ctxt)
throws JsonMappingException
{
throw InvalidFormatException.from(ctxt.getParser(),
String.format("UUID has to be represented by standard 36-char representation: input String '%s'",
uuidStr),
uuidStr, handledType());
}
static int intFromChars(String str, int index, DeserializationContext ctxt) throws JsonMappingException {
return (byteFromChars(str, index, ctxt) << 24)
+ (byteFromChars(str, index+2, ctxt) << 16)
+ (byteFromChars(str, index+4, ctxt) << 8)
+ byteFromChars(str, index+6, ctxt);
}
static int shortFromChars(String str, int index, DeserializationContext ctxt) throws JsonMappingException {
return (byteFromChars(str, index, ctxt) << 8) + byteFromChars(str, index+2, ctxt);
}
static int byteFromChars(String str, int index, DeserializationContext ctxt) throws JsonMappingException
{
final char c1 = str.charAt(index);
final char c2 = str.charAt(index+1);
if (c1 <= 127 && c2 <= 127) {
int hex = (HEX_DIGITS[c1] << 4) | HEX_DIGITS[c2];
if (hex >= 0) {
return hex;
}
}
if (c1 > 127 || HEX_DIGITS[c1] < 0) {
return _badChar(str, index, ctxt, c
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>1);
}
return _badChar(str, index+1, ctxt, c2);
}
static int _badChar(String uuidStr, int index, DeserializationContext ctxt, char c) throws JsonMappingException {
String msg = String.format(
"Non-hex character '%c' (value 0x%s), not valid for UUID String: input String '%s'",
c, Integer.toHexString(c), uuidStr);
throw InvalidFormatException.from(ctxt.getParser(), msg, uuidStr, UUID.class);
}
private UUID _fromBytes(byte[] bytes, DeserializationContext ctxt) throws JsonMappingException {
if (bytes.length != 16) {
throw InvalidFormatException.from(ctxt.getParser(),
"Can only construct UUIDs from byte[16]; got "+bytes.length+" bytes",
bytes, handledType());
}
return new UUID(_long(bytes, 0), _long(bytes, 8));
}
private static long _long(byte[] b, int offset) {
long l1 = ((long) _int(b, offset)) << 32;
long l2 = _int(b, offset+4);
// faster to just do it than check if it has sign
l2 = (l2 << 32) >>> 32; // to get rid of sign
return l1 | l2;
}
private static int _int(byte[] b, int offset) {
return (b[offset] << 24) | ((b[offset+1] & 0xFF) << 16) | ((b[offset+2] & 0xFF) << 8) | (b[offset+3] & 0xFF);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.util.UUID;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.util.TokenBuffer;
/**
* Specialized {@link JsonSerializer} to output {@link java.util.UUID}s.
* Beyond optimized access and writing of textual representation (which
* is the default handling in most cases), it will alternatively
* allow serialization using raw binary output (as 16-byte block)
* if underlying data format has efficient means to access that.
*/
@SuppressWarnings("serial")
public class UUIDSerializer
extends StdScalarSerializer<UUID>
{
final static char[] HEX_CHARS = "0123456789abcdef".toCharArray();
public UUIDSerializer() { super(UUID.class); }
@Override
public boolean isEmpty(SerializerProvider prov, UUID value)
{
if (value == null) {
return true;
}
// Null UUID is empty, so...
if (value.getLeastSignificantBits() == 0L
&& value.getMostSignificantBits() == 0L) {
return true;
}
return false;
}
@Override
public void serialize(UUID value, JsonGenerator gen, SerializerProvider provider)
throws IOException
{
// First: perhaps we could serialize it as raw binary data?
if (gen.canWriteBinaryNatively()) {
/* 07-Dec-2013, tatu: One nasty case; that of TokenBuffer. While it can
* technically retain binary data, we do not want to do use binary
* with it, as that results in UUIDs getting converted to Base64 for
* most conversions.
*/
if (!(gen instanceof TokenBuffer)) {
gen.writeBinary(_asBytes(value));
return;
}
}
// UUID.toString() works ok functionally, but we can make it go much faster
// (by 4x with micro-benchmark)
final char[] ch = new char[36];
final long msb = value.getMostSignificantBits();
_appendInt((int) (msb >> 32), ch, 0);
ch[8] = '-';
int i = (int) msb;
_appendShort(i >>> 16, ch, 9);
ch[13] = '-';
_appendShort(
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>i, ch, 14);
ch[18] = '-';
final long lsb = value.getLeastSignificantBits();
_appendShort((int) (lsb >>> 48), ch, 19);
ch[23] = '-';
_appendShort((int) (lsb >>> 32), ch, 24);
_appendInt((int) lsb, ch, 28);
gen.writeString(ch, 0, 36);
}
private static void _appendInt(int bits, char[] ch, int offset)
{
_appendShort(bits >> 16, ch, offset);
_appendShort(bits, ch, offset+4);
}
private static void _appendShort(int bits, char[] ch, int offset)
{
ch[offset] = HEX_CHARS[(bits >> 12) & 0xF];
ch[++offset] = HEX_CHARS[(bits >> 8) & 0xF];
ch[++offset] = HEX_CHARS[(bits >> 4) & 0xF];
ch[++offset] = HEX_CHARS[bits & 0xF];
}
private final static byte[] _asBytes(UUID uuid)
{
byte[] buffer = new byte[16];
long hi = uuid.getMostSignificantBits();
long lo = uuid.getLeastSignificantBits();
_appendInt((int) (hi >> 32), buffer, 0);
_appendInt((int) hi, buffer, 4);
_appendInt((int) (lo >> 32), buffer, 8);
_appendInt((int) lo, buffer, 12);
return buffer;
}
private final static void _appendInt(int value, byte[] buffer, int offset)
{
buffer[offset] = (byte) (value >> 24);
buffer[++offset] = (byte) (value >> 16);
buffer[++offset] = (byte) (value >> 8);
buffer[++offset] = (byte) value;
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>)
throws IOException
{
return _parseShort(jp, ctxt);
}
}
@JacksonStdImpl
public static class CharacterDeserializer
extends PrimitiveOrWrapperDeserializer<Character>
{
private static final long serialVersionUID = 1L;
final static CharacterDeserializer primitiveInstance = new CharacterDeserializer(Character.TYPE, '\0');
final static CharacterDeserializer wrapperInstance = new CharacterDeserializer(Character.class, null);
public CharacterDeserializer(Class<Character> cls, Character nvl)
{
super(cls, nvl);
}
@Override
public Character deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT: // ok iff ascii value
int value = p.getIntValue();
if (value >= 0 && value <= 0xFFFF) {
return Character.valueOf((char) value);
}
break;
case JsonTokenId.ID_STRING: // this is the usual type
// But does it have to be exactly one char?
String text = p.getText();
if (text.length() == 1) {
return Character.valueOf(text.charAt(0));
}
// actually, empty should become null?
if (text.length() == 0) {
return (Character) getEmptyValue(ctxt);
}
break;
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final Character C = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single '" + _valueClass.getName() + "' value but there was more than a single value in the array"
);
}
return C;
}
}
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
}
@JacksonStdImpl
public final static class IntegerDeserializer
extends PrimitiveOrWrapperDeserializer<Integer>
{
private static final long serialVersionUID = 1L;
final static IntegerDeserializer primitiveInstance = new IntegerDeserializer(Integer.TYPE, Integer.valueOf(0));
final static IntegerDeserializer wrapperInstance = new IntegerDeserializer(Integer.class, null);
public IntegerDeserializer(Class<Integer> cls, Integer nvl) {
super(cls, nvl);
}
// since 2.6, slightly faster look
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>.d);
final static DoubleDeserializer wrapperInstance = new DoubleDeserializer(Double.class, null);
public DoubleDeserializer(Class<Double> cls, Double nvl) {
super(cls, nvl);
}
@Override
public Double deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
return _parseDouble(jp, ctxt);
}
// Since we can never have type info ("natural type"; String, Boolean, Integer, Double):
// (is it an error to even call this version?)
@Override
public Double deserializeWithType(JsonParser jp, DeserializationContext ctxt,
TypeDeserializer typeDeserializer) throws IOException
{
return _parseDouble(jp, ctxt);
}
}
/**
* For type <code>Number.class</code>, we can just rely on type
* mappings that plain {@link JsonParser#getNumberValue} returns.
*<p>
* There is one additional complication: some numeric
* types (specifically, int/Integer and double/Double) are "non-typed";
* meaning that they will NEVER be output with type information.
* But other numeric types may need such type information.
* This is why {@link #deserializeWithType} must be overridden.
*/
@SuppressWarnings("serial")
@JacksonStdImpl
public static class NumberDeserializer
extends StdScalarDeserializer<Object>
{
public final static NumberDeserializer instance = new NumberDeserializer();
public NumberDeserializer() {
super(Number.class);
}
@Override
public Object deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
if (ctxt.hasSomeOfFeatures(F_MASK_INT_COERCIONS)) {
return _coerceIntegral(p, ctxt);
}
return p.getNumberValue();
case JsonTokenId.ID_NUMBER_FLOAT:
if (ctxt.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)) {
return p.getDecimalValue();
}
return Double.valueOf(p.getDoubleValue());
case JsonTokenId.ID_STRING:
/* Textual values are more difficult... not parsing itself, but figuring
* out 'minimal' type to use
*/
String text = p.getText().trim();
if (text.length() == 0) {
return getEmptyValue(ctxt);
}
if (_hasTextualNull(text)) {
return getNullValue(ctxt);
}
if (_isPosInf(text)) {
return Double.
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
/**********************************************************
/* And then bit more complicated (but non-structured) number
/* types
/**********************************************************
*/
/**
* This is bit trickier to implement efficiently, while avoiding
* overflow problems.
*/
@SuppressWarnings("serial")
@JacksonStdImpl
public static class BigIntegerDeserializer
extends StdScalarDeserializer<BigInteger>
{
public final static BigIntegerDeserializer instance = new BigIntegerDeserializer();
public BigIntegerDeserializer() { super(BigInteger.class); }
@SuppressWarnings("incomplete-switch")
@Override
public BigInteger deserialize(JsonParser p, DeserializationContext ctxt) throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
switch (p.getNumberType()) {
case INT:
case LONG:
case BIG_INTEGER:
return p.getBigIntegerValue();
}
break;
case JsonTokenId.ID_NUMBER_FLOAT:
if (!ctxt.isEnabled(DeserializationFeature.ACCEPT_FLOAT_AS_INT)) {
_failDoubleToIntCoercion(p, ctxt, "java.math.BigInteger");
}
return p.getDecimalValue().toBigInteger();
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final BigInteger value = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'BigInteger' value but there was more than a single value in the array"
);
}
return value;
}
break;
case JsonTokenId.ID_STRING: // let's do implicit re-parse
String text = p.getText().trim();
if (text.length() == 0) {
return null;
}
try {
return new BigInteger(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid representation");
}
}
// String is ok too, can easily convert; otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
}
@SuppressWarnings("serial")
@JacksonStdImpl
public static class BigDecimalDeserializer
extends StdScalarDeserializer<BigDecimal>
{
public final static BigDecimalDeserializer instance = new BigDecimalDeserializer();
public BigDecimalDeserializer() { super(BigDecimal.class); }
@Override
public BigDecimal deserialize(Json
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Parser p, DeserializationContext ctxt)
throws IOException
{
switch (p.getCurrentTokenId()) {
case JsonTokenId.ID_NUMBER_INT:
case JsonTokenId.ID_NUMBER_FLOAT:
return p.getDecimalValue();
case JsonTokenId.ID_STRING:
String text = p.getText().trim();
if (text.length() == 0) {
return null;
}
try {
return new BigDecimal(text);
} catch (IllegalArgumentException iae) {
throw ctxt.weirdStringException(text, _valueClass, "not a valid representation");
}
case JsonTokenId.ID_START_ARRAY:
if (ctxt.isEnabled(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS)) {
p.nextToken();
final BigDecimal value = deserialize(p, ctxt);
if (p.nextToken() != JsonToken.END_ARRAY) {
throw ctxt.wrongTokenException(p, JsonToken.END_ARRAY,
"Attempted to unwrap single value array for single 'BigDecimal' value but there was more than a single value in the array"
);
}
return value;
}
break;
}
// Otherwise, no can do:
throw ctxt.mappingException(_valueClass, p.getCurrentToken());
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
}
}
return bindings.resolveType(getGenericType());
}
*/
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
public final AnnotationMap getParameterAnnotations(int index)
{
if (_paramAnnotations != null) {
if (index >= 0 && index < _paramAnnotations.length) {
return _paramAnnotations[index];
}
}
return null;
}
public final AnnotatedParameter getParameter(int index) {
return new AnnotatedParameter(this, getParameterType(index),
getParameterAnnotations(index), index);
}
public abstract int getParameterCount();
public abstract Class<?> getRawParameterType(int index);
/**
* @since 2.7
*/
public abstract JavaType getParameterType(int index);
/**
* @deprecated Since 2.7, remove in 2.8
*/
@Deprecated
public abstract Type getGenericParameterType(int index);
public final int getAnnotationCount() { return _annotations.size(); }
/**
* Method that can be used to (try to) call this object without arguments.
* This may succeed or fail, depending on expected number
* of arguments: caller needs to take care to pass correct number.
* Exceptions are thrown directly from actual low-level call.
*<p>
* Note: only works for constructors and static methods.
*/
public abstract Object call() throws Exception;
/**
* Method that can be used to (try to) call this object with specified arguments.
* This may succeed or fail, depending on expected number
* of arguments: caller needs to take care to pass correct number.
* Exceptions are thrown directly from actual low-level call.
*<p>
* Note: only works for constructors and static methods.
*/
public abstract Object call(Object[] args) throws Exception;
/**
* Method that can be used to (try to) call this object with single arguments.
* This may succeed or fail, depending on expected number
* of arguments: caller needs to take care to pass correct number.
* Exceptions are thrown directly from actual low-level call.
*<p>
* Note: only works for constructors and static methods.
*/
public abstract Object call1(Object arg) throws Exception;
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Writer> props)
throws JsonMappingException
{
ObjectIdInfo objectIdInfo = beanDesc.getObjectIdInfo();
if (objectIdInfo == null) {
return null;
}
ObjectIdGenerator<?> gen;
Class<?> implClass = objectIdInfo.getGeneratorType();
// Just one special case: Property-based generator is trickier
if (implClass == ObjectIdGenerators.PropertyGenerator.class) { // most special one, needs extra work
String propName = objectIdInfo.getPropertyName().getSimpleName();
BeanPropertyWriter idProp = null;
for (int i = 0, len = props.size() ;; ++i) {
if (i == len) {
throw new IllegalArgumentException("Invalid Object Id definition for "+beanDesc.getBeanClass().getName()
+": can not find property with name '"+propName+"'");
}
BeanPropertyWriter prop = props.get(i);
if (propName.equals(prop.getName())) {
idProp = prop;
/* Let's force it to be the first property to output
* (although it may still get rearranged etc)
*/
if (i > 0) {
props.remove(i);
props.add(0, idProp);
}
break;
}
}
JavaType idType = idProp.getType();
gen = new PropertyBasedObjectIdGenerator(objectIdInfo, idProp);
// one more thing: must ensure that ObjectIdWriter does not actually write the value:
return ObjectIdWriter.construct(idType, (PropertyName) null, gen, objectIdInfo.getAlwaysAsId());
}
// other types are simpler
JavaType type = prov.constructType(implClass);
// Could require type to be passed explicitly, but we should be able to find it too:
JavaType idType = prov.getTypeFactory().findTypeParameters(type, ObjectIdGenerator.class)[0];
gen = prov.objectIdGeneratorInstance(beanDesc.getClassInfo(), objectIdInfo);
return ObjectIdWriter.construct(idType, objectIdInfo.getPropertyName(), gen,
objectIdInfo.getAlwaysAsId());
}
/**
* Method called to construct a filtered writer, for given view
* definitions. Default implementation constructs filter that checks
* active view type to views property is to be included in.
*/
protected BeanPropertyWriter constructFilteredBeanWriter(BeanPropertyWriter writer,
Class<?>[] inViews)
{
return FilteredBeanPropertyWriter.constructViewBased(writer, inViews);
}
protected PropertyBuilder constructPropertyBuilder(SerializationConfig config,
BeanDescription beanDesc
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>) {
accessor.fixAccess(forceAccess);
}
builder.setTypeId(accessor);
}
continue;
}
// suppress writing of back references
AnnotationIntrospector.ReferenceProperty refType = property.findReferenceType();
if (refType != null && refType.isBackReference()) {
continue;
}
if (accessor instanceof AnnotatedMethod) {
result.add(_constructWriter(prov, property, pb, staticTyping, (AnnotatedMethod) accessor));
} else {
result.add(_constructWriter(prov, property, pb, staticTyping, (AnnotatedField) accessor));
}
}
return result;
}
/*
/**********************************************************
/* Overridable non-public methods for manipulating bean properties
/**********************************************************
*/
/**
* Overridable method that can filter out properties. Default implementation
* checks annotations class may have.
*/
protected List<BeanPropertyWriter> filterBeanProperties(SerializationConfig config,
BeanDescription beanDesc, List<BeanPropertyWriter> props)
{
AnnotationIntrospector intr = config.getAnnotationIntrospector();
AnnotatedClass ac = beanDesc.getClassInfo();
String[] ignored = intr.findPropertiesToIgnore(ac, true);
if (ignored != null && ignored.length > 0) {
HashSet<String> ignoredSet = ArrayBuilders.arrayToSet(ignored);
Iterator<BeanPropertyWriter> it = props.iterator();
while (it.hasNext()) {
if (ignoredSet.contains(it.next().getName())) {
it.remove();
}
}
}
return props;
}
/**
* Method called to handle view information for constructed serializer,
* based on bean property writers.
*<p>
* Note that this method is designed to be overridden by sub-classes
* if they want to provide custom view handling. As such it is not
* considered an internal implementation detail, and will be supported
* as part of API going forward.
*/
protected void processViews(SerializationConfig config, BeanSerializerBuilder builder)
{
// [JACKSON-232]: whether non-annotated fields are included by default or not is configurable
List<BeanPropertyWriter> props = builder.getProperties();
boolean includeByDefault = config.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION);
final int propCount = props.size();
int viewsFound = 0;
BeanPropertyWriter[] filtered = new BeanPropertyWriter[propCount];
// Simple: view information is stored within individual writers, need to combine:
for (int i
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> = 0; i < propCount; ++i) {
BeanPropertyWriter bpw = props.get(i);
Class<?>[] views = bpw.getViews();
if (views == null) { // no view info? include or exclude by default?
if (includeByDefault) {
filtered[i] = bpw;
}
} else {
++viewsFound;
filtered[i] = constructFilteredBeanWriter(bpw, views);
}
}
// minor optimization: if no view info, include-by-default, can leave out filtering info altogether:
if (includeByDefault && viewsFound == 0) {
return;
}
builder.setFilteredProperties(filtered);
}
/**
* Method that will apply by-type limitations (as per [JACKSON-429]);
* by default this is based on {@link com.fasterxml.jackson.annotation.JsonIgnoreType}
* annotation but can be supplied by module-provided introspectors too.
*/
protected void removeIgnorableTypes(SerializationConfig config, BeanDescription beanDesc,
List<BeanPropertyDefinition> properties)
{
AnnotationIntrospector intr = config.getAnnotationIntrospector();
HashMap<Class<?>,Boolean> ignores = new HashMap<Class<?>,Boolean>();
Iterator<BeanPropertyDefinition> it = properties.iterator();
while (it.hasNext()) {
BeanPropertyDefinition property = it.next();
AnnotatedMember accessor = property.getAccessor();
if (accessor == null) {
it.remove();
continue;
}
Class<?> type = accessor.getRawType();
Boolean result = ignores.get(type);
if (result == null) {
BeanDescription desc = config.introspectClassAnnotations(type);
AnnotatedClass ac = desc.getClassInfo();
result = intr.isIgnorableType(ac);
// default to false, non-ignorable
if (result == null) {
result = Boolean.FALSE;
}
ignores.put(type, result);
}
// lotsa work, and yes, it is ignorable type, so:
if (result.booleanValue()) {
it.remove();
}
}
}
/**
* Helper method that will remove all properties that do not have a mutator.
*/
protected void removeSetterlessGetters(SerializationConfig config, BeanDescription beanDesc,
List<BeanPropertyDefinition> properties)
{
Iterator<BeanPropertyDefinition> it = properties.iterator();
while (it.hasNext()) {
BeanPropertyDefinition property = it.next();
// one cave
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>at: as per [JACKSON-806], only remove implicit properties;
// explicitly annotated ones should remain
if (!property.couldDeserialize() && !property.isExplicitlyIncluded()) {
it.remove();
}
}
}
/**
* Helper method called to ensure that we do not have "duplicate" type ids.
* Added to resolve [databind#222]
*
* @since 2.6
*/
protected List<BeanPropertyWriter> removeOverlappingTypeIds(SerializerProvider prov,
BeanDescription beanDesc, BeanSerializerBuilder builder,
List<BeanPropertyWriter> props)
{
for (int i = 0, end = props.size(); i < end; ++i) {
BeanPropertyWriter bpw = props.get(i);
TypeSerializer td = bpw.getTypeSerializer();
if ((td == null) || (td.getTypeInclusion() != As.EXTERNAL_PROPERTY)) {
continue;
}
String n = td.getPropertyName();
PropertyName typePropName = PropertyName.construct(n);
for (BeanPropertyWriter w2 : props) {
if ((w2 != bpw) && w2.wouldConflictWithName(typePropName)) {
bpw.assignTypeSerializer(null);
break;
}
}
}
return props;
}
/*
/**********************************************************
/* Internal helper methods
/**********************************************************
*/
/**
* Secondary helper method for constructing {@link BeanPropertyWriter} for
* given member (field or method).
*/
protected BeanPropertyWriter _constructWriter(SerializerProvider prov,
BeanPropertyDefinition propDef,
PropertyBuilder pb, boolean staticTyping, AnnotatedMember accessor)
throws JsonMappingException
{
final PropertyName name = propDef.getFullName();
if (prov.canOverrideAccessModifiers()) {
accessor.fixAccess(prov.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS));
}
JavaType type = accessor.getType();
BeanProperty.Std property = new BeanProperty.Std(name, type, propDef.getWrapperName(),
pb.getClassAnnotations(), accessor, propDef.getMetadata());
// Does member specify a serializer? If so, let's use it.
JsonSerializer<?> annotatedSerializer = findSerializerFromAnnotation(prov,
accessor);
// Unlike most other code paths, serializer produced
// here will NOT be resolved or contextualized, unless done here, so:
if (annotatedSerializer instanceof ResolvableSerializer) {
((ResolvableSerializer) annotatedSerializer).resolve(prov);
}
// 0
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
protected final Class<?> _view;
/**
* Contextual attributes accessible (get and set) during processing,
* on per-call basis.
*
* @since 2.3
*/
protected final ContextAttributes _attributes;
/**
* @since 2.6
*/
protected final RootNameLookup _rootNames;
/*
/**********************************************************
/* Construction
/**********************************************************
*/
/**
* Constructor used when creating a new instance (compared to
* that of creating fluent copies)
*/
protected MapperConfigBase(BaseSettings base,
SubtypeResolver str, SimpleMixInResolver mixins,
RootNameLookup rootNames)
{
super(base, DEFAULT_MAPPER_FEATURES);
_mixIns = mixins;
_subtypeResolver = str;
_rootNames = rootNames;
_rootName = null;
_view = null;
// default to "no attributes"
_attributes = ContextAttributes.getEmpty();
}
/**
* Pass-through constructor used when no changes are needed to the
* base class.
*/
protected MapperConfigBase(MapperConfigBase<CFG,T> src)
{
super(src);
_mixIns = src._mixIns;
_subtypeResolver = src._subtypeResolver;
_rootNames = src._rootNames;
_rootName = src._rootName;
_view = src._view;
_attributes = src._attributes;
}
protected MapperConfigBase(MapperConfigBase<CFG,T> src, BaseSettings base)
{
super(src, base);
_mixIns = src._mixIns;
_subtypeResolver = src._subtypeResolver;
_rootNames = src._rootNames;
_rootName = src._rootName;
_view = src._view;
_attributes = src._attributes;
}
protected MapperConfigBase(MapperConfigBase<CFG,T> src, int mapperFeatures)
{
super(src, mapperFeatures);
_mixIns = src._mixIns;
_subtypeResolver = src._subtypeResolver;
_rootNames = src._rootNames;
_rootName = src._rootName;
_view = src._view;
_attributes = src._attributes;
}
protected MapperConfigBase(MapperConfigBase<CFG,T> src, SubtypeResolver str) {
super(src);
_mixIns = src._mixIns;
_subtypeResolver = str;
_rootNames = src._rootNames;
_rootName = src._rootName;
_view = src._view;
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>since 2.6
*/
public abstract T withRootName(PropertyName rootName);
public T withRootName(String rootName) {
if (rootName == null) {
return withRootName((PropertyName) null);
}
return withRootName(PropertyName.construct(rootName));
}
/**
* Method for constructing and returning a new instance with different
* {@link SubtypeResolver}
* to use.
*<p>
* NOTE: make sure to register new instance with <code>ObjectMapper</code>
* if directly calling this method.
*/
public abstract T with(SubtypeResolver str);
/**
* Method for constructing and returning a new instance with different
* {@link TypeFactory}
* to use.
*/
public abstract T with(TypeFactory typeFactory);
/**
* Method for constructing and returning a new instance with different
* {@link TypeResolverBuilder} to use.
*/
public abstract T with(TypeResolverBuilder<?> trb);
/**
* Method for constructing and returning a new instance with different
* view to use.
*/
public abstract T withView(Class<?> view);
/**
* Method for constructing and returning a new instance with different
* {@link VisibilityChecker}
* to use.
*/
public abstract T with(VisibilityChecker<?> vc);
/**
* Method for constructing and returning a new instance with different
* minimal visibility level for specified property type
*/
public abstract T withVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility);
/**
* Method for constructing and returning a new instance with different
* default {@link java.util.Locale} to use for formatting.
*/
public abstract T with(Locale l);
/**
* Method for constructing and returning a new instance with different
* default {@link java.util.TimeZone} to use for formatting of date values.
*/
public abstract T with(TimeZone tz);
/**
* Method for constructing and returning a new instance with different
* default {@link Base64Variant} to use with base64-encoded binary values.
*/
public abstract T with(Base64Variant base64);
/**
* Method for constructing an instance that has specified
* contextual attributes.
*
* @since 2.3
*/
public abstract T with(ContextAttributes attrs);
/**
* Method for constructing an instance that has only specified
* attributes, removing any attributes that exist before the call.
*
* @since 2.3
*/
public T withAttributes(Map<?,?> attributes) {
return with(getAttributes().with
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>class);
// Constructor also always members of this class
TypeResolutionContext typeContext = this;
// 30-Apr-2016, tatu: [databind#1215]: Actually, while true, this does
// NOT apply to context since sub-class may have type bindings
// TypeResolutionContext typeContext = new TypeResolutionContext.Basic(_typeFactory, _type.getBindings());
for (ClassUtil.Ctor ctor : declaredCtors) {
if (_isIncludableConstructor(ctor.getConstructor())) {
if (ctor.getParamCount() == 0) {
_defaultConstructor = _constructDefaultConstructor(ctor, typeContext);
} else {
if (constructors == null) {
constructors = new ArrayList<AnnotatedConstructor>(Math.max(10, declaredCtors.length));
}
constructors.add(_constructNonDefaultConstructor(ctor, typeContext));
}
}
}
if (constructors == null) {
_constructors = Collections.emptyList();
} else {
_constructors = constructors;
}
// and if need be, augment with mix-ins
if (_primaryMixIn != null) {
if (_defaultConstructor != null || !_constructors.isEmpty()) {
_addConstructorMixIns(_primaryMixIn);
}
}
/* And then... let's remove all constructors that are deemed
* ignorable after all annotations have been properly collapsed.
*/
// AnnotationIntrospector is null if annotations not enabled; if so, can skip:
if (_annotationIntrospector != null) {
if (_defaultConstructor != null) {
if (_annotationIntrospector.hasIgnoreMarker(_defaultConstructor)) {
_defaultConstructor = null;
}
}
if (_constructors != null) {
// count down to allow safe removal
for (int i = _constructors.size(); --i >= 0; ) {
if (_annotationIntrospector.hasIgnoreMarker(_constructors.get(i))) {
_constructors.remove(i);
}
}
}
}
List<AnnotatedMethod> creatorMethods = null;
// Then static methods which are potential factory methods
for (Method m : _findClassMethods(_class)) {
if (!Modifier.isStatic(m.getModifiers())) {
continue;
}
// all factory methods are fine:
//int argCount = m.getParameterTypes().length;
if (creatorMethods == null) {
creatorMethods = new ArrayList<AnnotatedMethod>(8);
}
creatorMethods.add(_constructCreatorMethod(
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>m, typeContext));
}
if (creatorMethods == null) {
_creatorMethods = Collections.emptyList();
} else {
_creatorMethods = creatorMethods;
// mix-ins to mix in?
if (_primaryMixIn != null) {
_addFactoryMixIns(_primaryMixIn);
}
// anything to ignore at this point?
if (_annotationIntrospector != null) {
// count down to allow safe removal
for (int i = _creatorMethods.size(); --i >= 0; ) {
if (_annotationIntrospector.hasIgnoreMarker(_creatorMethods.get(i))) {
_creatorMethods.remove(i);
}
}
}
}
_creatorsResolved = true;
}
/**
* Method for resolving member method information: aggregating all non-static methods
* and combining annotations (to implement method-annotation inheritance)
*
* @param methodFilter Filter used to determine which methods to include
*/
private void resolveMemberMethods()
{
_memberMethods = new AnnotatedMethodMap();
AnnotatedMethodMap mixins = new AnnotatedMethodMap();
// first: methods from the class itself
_addMemberMethods(_class, this, _memberMethods, _primaryMixIn, mixins);
// and then augment these with annotations from super-types:
for (JavaType type : _superTypes) {
Class<?> mixin = (_mixInResolver == null) ? null : _mixInResolver.findMixInClassFor(type.getRawClass());
_addMemberMethods(type.getRawClass(),
new TypeResolutionContext.Basic(_typeFactory, type.getBindings()),
_memberMethods, mixin, mixins);
}
// Special case: mix-ins for Object.class? (to apply to ALL classes)
if (_mixInResolver != null) {
Class<?> mixin = _mixInResolver.findMixInClassFor(Object.class);
if (mixin != null) {
_addMethodMixIns(_class, _memberMethods, mixin, mixins);
}
}
/* Any unmatched mix-ins? Most likely error cases (not matching
* any method); but there is one possible real use case:
* exposing Object#hashCode (alas, Object#getClass can NOT be
* exposed)
*/
// 14-Feb-2011, tatu: AnnotationIntrospector is null if annotations not enabled; if so, can skip:
if (_annotationIntrospector != null) {
if (!mixins.isEmpty()) {
Iterator<AnnotatedMethod> it = mixins.iterator();
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> is a sub-class (for convenience reasons). And if so, we
* absolutely must NOT include super types of masked class,
* as that would inverse precedence of annotations.
*/
for (Class<?> parent : ClassUtil.findSuperClasses(mixin, toMask, false)) {
_addAnnotationsIfNotPresent(annotations, ClassUtil.findClassAnnotations(parent));
}
}
/*
/**********************************************************
/* Helper methods for populating creator (ctor, factory) information
/**********************************************************
*/
protected void _addConstructorMixIns(Class<?> mixin)
{
MemberKey[] ctorKeys = null;
int ctorCount = (_constructors == null) ? 0 : _constructors.size();
for (ClassUtil.Ctor ctor0 : ClassUtil.getConstructors(mixin)) {
Constructor<?> ctor = ctor0.getConstructor();
if (ctor.getParameterTypes().length == 0) {
if (_defaultConstructor != null) {
_addMixOvers(ctor, _defaultConstructor, false);
}
} else {
if (ctorKeys == null) {
ctorKeys = new MemberKey[ctorCount];
for (int i = 0; i < ctorCount; ++i) {
ctorKeys[i] = new MemberKey(_constructors.get(i).getAnnotated());
}
}
MemberKey key = new MemberKey(ctor);
for (int i = 0; i < ctorCount; ++i) {
if (!key.equals(ctorKeys[i])) {
continue;
}
_addMixOvers(ctor, _constructors.get(i), true);
break;
}
}
}
}
protected void _addFactoryMixIns(Class<?> mixin)
{
MemberKey[] methodKeys = null;
int methodCount = _creatorMethods.size();
for (Method m : ClassUtil.getDeclaredMethods(mixin)) {
if (!Modifier.isStatic(m.getModifiers())) {
continue;
}
if (m.getParameterTypes().length == 0) {
continue;
}
if (methodKeys == null) {
methodKeys = new MemberKey[methodCount];
for (int i = 0; i < methodCount; ++i) {
methodKeys[i] = new MemberKey(_creatorMethods.get(i).getAnnotated());
}
}
MemberKey key = new MemberKey(m);
for (int i = 0; i < methodCount; ++i) {
if (!key.equals(methodKeys[i])) {
continue;
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
}
_addMixOvers(m, _creatorMethods.get(i), true);
break;
}
}
}
/*
/**********************************************************
/* Helper methods for populating method information
/**********************************************************
*/
protected void _addMemberMethods(Class<?> cls, TypeResolutionContext typeContext,
AnnotatedMethodMap methods,
Class<?> mixInCls, AnnotatedMethodMap mixIns)
{
// first, mixIns, since they have higher priority then class methods
if (mixInCls != null) {
_addMethodMixIns(cls, methods, mixInCls, mixIns);
}
if (cls == null) { // just so caller need not check when passing super-class
return;
}
// then methods from the class itself
for (Method m : _findClassMethods(cls)) {
if (!_isIncludableMemberMethod(m)) {
continue;
}
AnnotatedMethod old = methods.find(m);
if (old == null) {
AnnotatedMethod newM = _constructMethod(m, typeContext);
methods.add(newM);
// Ok, but is there a mix-in to connect now?
old = mixIns.remove(m);
if (old != null) {
_addMixOvers(old.getAnnotated(), newM, false);
}
} else {
/* If sub-class already has the method, we only want to augment
* annotations with entries that are not masked by sub-class.
*/
_addMixUnders(m, old);
/* 06-Jan-2010, tatu: [JACKSON-450] Except that if method we saw first is
* from an interface, and we now find a non-interface definition, we should
* use this method, but with combination of annotations.
* This helps (or rather, is essential) with JAXB annotations and
* may also result in faster method calls (interface calls are slightly
* costlier than regular method calls)
*/
if (old.getDeclaringClass().isInterface() && !m.getDeclaringClass().isInterface()) {
methods.add(old.withMethod(m));
}
}
}
}
protected void _addMethodMixIns(Class<?> targetClass, AnnotatedMethodMap methods,
Class<?> mixInCls, AnnotatedMethodMap mixIns)
{
// List<Class<?>> parents = ClassUtil.findSuperClasses(mixInCls, targetClass, true);
List<Class<?>>
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
TypeResolutionContext typeContext)
{
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedConstructor(typeContext, ctor.getConstructor(), _emptyAnnotationMap(), NO_ANNOTATION_MAPS);
}
return new AnnotatedConstructor(typeContext, ctor.getConstructor(),
_collectRelevantAnnotations(ctor.getDeclaredAnnotations()), NO_ANNOTATION_MAPS);
}
protected AnnotatedConstructor _constructNonDefaultConstructor(ClassUtil.Ctor ctor,
TypeResolutionContext typeContext)
{
final int paramCount = ctor.getParamCount();
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedConstructor(typeContext, ctor.getConstructor(),
_emptyAnnotationMap(), _emptyAnnotationMaps(paramCount));
}
/* Looks like JDK has discrepancy, whereas annotations for implicit 'this'
* (for non-static inner classes) are NOT included, but type is?
* Strange, sounds like a bug. Alas, we can't really fix that...
*/
if (paramCount == 0) { // no-arg default constructors, can simplify slightly
return new AnnotatedConstructor(typeContext, ctor.getConstructor(),
_collectRelevantAnnotations(ctor.getDeclaredAnnotations()), NO_ANNOTATION_MAPS);
}
// Also: enum value constructors
AnnotationMap[] resolvedAnnotations;
Annotation[][] paramAnns = ctor.getParameterAnnotations();
if (paramCount != paramAnns.length) {
// Limits of the work-around (to avoid hiding real errors):
// first, only applicable for member classes and then either:
resolvedAnnotations = null;
Class<?> dc = ctor.getDeclaringClass();
// (a) is enum, which have two extra hidden params (name, index)
if (dc.isEnum() && (paramCount == paramAnns.length + 2)) {
Annotation[][] old = paramAnns;
paramAnns = new Annotation[old.length+2][];
System.arraycopy(old, 0, paramAnns, 2, old.length);
resolvedAnnotations = _collectRelevantAnnotations(paramAnns);
} else if (dc.isMemberClass()) {
// (b) non-static inner classes, get implicit 'this' for parameter, not annotation
if (paramCount == (paramAnns.length + 1)) {
// hack attack: prepend a null entry to make things match
Annotation[][] old = paramAnns;
paramAnns = new Annotation[old
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>.length+1][];
System.arraycopy(old, 0, paramAnns, 1, old.length);
resolvedAnnotations = _collectRelevantAnnotations(paramAnns);
}
}
if (resolvedAnnotations == null) {
throw new IllegalStateException("Internal error: constructor for "+ctor.getDeclaringClass().getName()
+" has mismatch: "+paramCount+" parameters; "+paramAnns.length+" sets of annotations");
}
} else {
resolvedAnnotations = _collectRelevantAnnotations(paramAnns);
}
return new AnnotatedConstructor(typeContext, ctor.getConstructor(),
_collectRelevantAnnotations(ctor.getDeclaredAnnotations()), resolvedAnnotations);
}
protected AnnotatedMethod _constructCreatorMethod(Method m, TypeResolutionContext typeContext)
{
final int paramCount = m.getParameterTypes().length;
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedMethod(typeContext, m, _emptyAnnotationMap(), _emptyAnnotationMaps(paramCount));
}
if (paramCount == 0) { // common enough we can slightly optimize
return new AnnotatedMethod(typeContext, m, _collectRelevantAnnotations(m.getDeclaredAnnotations()),
NO_ANNOTATION_MAPS);
}
return new AnnotatedMethod(typeContext, m, _collectRelevantAnnotations(m.getDeclaredAnnotations()),
_collectRelevantAnnotations(m.getParameterAnnotations()));
}
protected AnnotatedField _constructField(Field f, TypeResolutionContext typeContext)
{
if (_annotationIntrospector == null) { // when annotation processing is disabled
return new AnnotatedField(typeContext, f, _emptyAnnotationMap());
}
return new AnnotatedField(typeContext, f, _collectRelevantAnnotations(f.getDeclaredAnnotations()));
}
private AnnotationMap _emptyAnnotationMap() {
return new AnnotationMap();
}
private AnnotationMap[] _emptyAnnotationMaps(int count) {
if (count == 0) {
return NO_ANNOTATION_MAPS;
}
AnnotationMap[] maps = new AnnotationMap[count];
for (int i = 0; i < count; ++i) {
maps[i] = _emptyAnnotationMap();
}
return maps;
}
/*
/**********************************************************
/* Helper methods, inclusion filtering
/**********************************************************
*/
protected boolean _isIncludableMemberMethod(Method m)
{
if (Modifier.isStatic(m.getModifiers())) {
return false;
}
/* 07-Apr-20
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>09, tatu: Looks like generics can introduce hidden
* bridge and/or synthetic methods. I don't think we want to
* consider those...
*/
if (m.isSynthetic() || m.isBridge()) {
return false;
}
// also, for now we have no use for methods with 2 or more arguments:
int pcount = m.getParameterTypes().length;
return (pcount <= 2);
}
private boolean _isIncludableField(Field f)
{
// Most likely synthetic fields, if any, are to be skipped similar to methods
if (f.isSynthetic()) {
return false;
}
// Static fields are never included. Transient are (since 2.6), for
// purpose of propagating removal
int mods = f.getModifiers();
if (Modifier.isStatic(mods)) {
return false;
}
return true;
}
// for [databind#1005]: do not use or expose synthetic constructors
private boolean _isIncludableConstructor(Constructor<?> c)
{
return !c.isSynthetic();
}
/*
/**********************************************************
/* Helper methods, attaching annotations
/**********************************************************
*/
protected AnnotationMap[] _collectRelevantAnnotations(Annotation[][] anns)
{
int len = anns.length;
AnnotationMap[] result = new AnnotationMap[len];
for (int i = 0; i < len; ++i) {
result[i] = _collectRelevantAnnotations(anns[i]);
}
return result;
}
protected AnnotationMap _collectRelevantAnnotations(Annotation[] anns)
{
return _addAnnotationsIfNotPresent(new AnnotationMap(), anns);
}
/* Helper method used to add all applicable annotations from given set.
* Takes into account possible "annotation bundles" (meta-annotations to
* include instead of main-level annotation)
*/
private AnnotationMap _addAnnotationsIfNotPresent(AnnotationMap result, Annotation[] anns)
{
if (anns != null) {
List<Annotation> fromBundles = null;
for (Annotation ann : anns) { // first: direct annotations
// note: we will NOT filter out non-Jackson anns any more
boolean wasNotPresent = result.addIfNotPresent(ann);
if (wasNotPresent && _isAnnotationBundle(ann)) {
fromBundles = _addFromBundle(ann, fromBundles);
}
}
if (fromBundles != null) { // and secondarily
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> handle bundles, if any found: precedence important
_addAnnotationsIfNotPresent(result, fromBundles.toArray(new Annotation[fromBundles.size()]));
}
}
return result;
}
private List<Annotation> _addFromBundle(Annotation bundle, List<Annotation> result)
{
for (Annotation a : ClassUtil.findClassAnnotations(bundle.annotationType())) {
// minor optimization: by-pass 2 common JDK meta-annotations
if ((a instanceof Target) || (a instanceof Retention)) {
continue;
}
if (result == null) {
result = new ArrayList<Annotation>();
}
result.add(a);
}
return result;
}
private void _addAnnotationsIfNotPresent(AnnotatedMember target, Annotation[] anns)
{
if (anns != null) {
List<Annotation> fromBundles = null;
for (Annotation ann : anns) { // first: direct annotations
boolean wasNotPresent = target.addIfNotPresent(ann);
if (wasNotPresent && _isAnnotationBundle(ann)) {
fromBundles = _addFromBundle(ann, fromBundles);
}
}
if (fromBundles != null) { // and secondarily handle bundles, if any found: precedence important
_addAnnotationsIfNotPresent(target, fromBundles.toArray(new Annotation[fromBundles.size()]));
}
}
}
private void _addOrOverrideAnnotations(AnnotatedMember target, Annotation[] anns)
{
if (anns != null) {
List<Annotation> fromBundles = null;
for (Annotation ann : anns) { // first: direct annotations
boolean wasModified = target.addOrOverride(ann);
if (wasModified && _isAnnotationBundle(ann)) {
fromBundles = _addFromBundle(ann, fromBundles);
}
}
if (fromBundles != null) { // and then bundles, if any: important for precedence
_addOrOverrideAnnotations(target, fromBundles.toArray(new Annotation[fromBundles.size()]));
}
}
}
/**
* @param addParamAnnotations Whether parameter annotations are to be
* added as well
*/
protected void _addMixOvers(Constructor<?> mixin, AnnotatedConstructor target,
boolean addParamAnnotations)
{
_addOrOverrideAnnotations(target, mixin.getDeclaredAnnotations());
if (addParamAnnotations) {
Annotation[][] pa = mixin.getParameterAnnotations();
for (int i = 0, len = pa.length; i < len;
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> ++i) {
for (Annotation a : pa[i]) {
target.addOrOverrideParam(i, a);
}
}
}
}
/**
* @param addParamAnnotations Whether parameter annotations are to be
* added as well
*/
protected void _addMixOvers(Method mixin, AnnotatedMethod target,
boolean addParamAnnotations)
{
_addOrOverrideAnnotations(target, mixin.getDeclaredAnnotations());
if (addParamAnnotations) {
Annotation[][] pa = mixin.getParameterAnnotations();
for (int i = 0, len = pa.length; i < len; ++i) {
for (Annotation a : pa[i]) {
target.addOrOverrideParam(i, a);
}
}
}
}
/**
* Method that will add annotations from specified source method to target method,
* but only if target does not yet have them.
*/
protected void _addMixUnders(Method src, AnnotatedMethod target) {
_addAnnotationsIfNotPresent(target, src.getDeclaredAnnotations());
}
private final boolean _isAnnotationBundle(Annotation ann) {
return (_annotationIntrospector != null) && _annotationIntrospector.isAnnotationBundle(ann);
}
/**
* Helper method that gets methods declared in given class; usually a simple thing,
* but sometimes (as per [databind#785]) more complicated, depending on classloader
* setup.
*
* @since 2.4.7
*/
protected Method[] _findClassMethods(Class<?> cls)
{
try {
return ClassUtil.getDeclaredMethods(cls);
} catch (final NoClassDefFoundError ex) {
// One of the methods had a class that was not found in the cls.getClassLoader.
// Maybe the developer was nice and has a different class loader for this context.
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null){
// Nope... this is going to end poorly
throw ex;
}
final Class<?> contextClass;
try {
contextClass = loader.loadClass(cls.getName());
} catch (ClassNotFoundException e) {
// !!! TODO: 08-May-2015, tatu: Chain appropriately once we have JDK 1.7/Java7 as baseline
//ex.addSuppressed(e); Not until Jackson 2.7
throw ex;
}
return contextClass.getDeclaredMethods(); // Cross fingers
}
}
/*
/**********************************************************
/* Other methods
/**********************************************************
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>, ctxt);
if (result != null) {
return result;
}
} catch (Exception re) {
throw ctxt.weirdKeyException(_keyClass, key, "not a valid representation: "+re.getMessage());
}
if (_keyClass.isEnum() && ctxt.getConfig().isEnabled(DeserializationFeature.READ_UNKNOWN_ENUM_VALUES_AS_NULL)) {
return null;
}
throw ctxt.weirdKeyException(_keyClass, key, "not a valid representation");
}
public Class<?> getKeyClass() { return _keyClass; }
protected Object _parse(String key, DeserializationContext ctxt) throws Exception
{
switch (_kind) {
case TYPE_BOOLEAN:
if ("true".equals(key)) {
return Boolean.TRUE;
}
if ("false".equals(key)) {
return Boolean.FALSE;
}
throw ctxt.weirdKeyException(_keyClass, key, "value not 'true' or 'false'");
case TYPE_BYTE:
{
int value = _parseInt(key);
// as per [JACKSON-804], allow range up to 255, inclusive
if (value < Byte.MIN_VALUE || value > 255) {
throw ctxt.weirdKeyException(_keyClass, key, "overflow, value can not be represented as 8-bit value");
}
return Byte.valueOf((byte) value);
}
case TYPE_SHORT:
{
int value = _parseInt(key);
if (value < Short.MIN_VALUE || value > Short.MAX_VALUE) {
throw ctxt.weirdKeyException(_keyClass, key, "overflow, value can not be represented as 16-bit value");
}
return Short.valueOf((short) value);
}
case TYPE_CHAR:
if (key.length() == 1) {
return Character.valueOf(key.charAt(0));
}
throw ctxt.weirdKeyException(_keyClass, key, "can only convert 1-character Strings");
case TYPE_INT:
return _parseInt(key);
case TYPE_LONG:
return _parseLong(key);
case TYPE_FLOAT:
// Bounds/range checks would be tricky here, so let's not bother even trying...
return Float.valueOf((float) _parseDouble(key));
case TYPE_DOUBLE:
return _parseDouble(key);
case TYPE_LOCALE:
try {
return _deser._deserialize(key, ctxt);
} catch (IOException e) {
throw
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>link IOException} into
* {@link JsonMappingException}: usually only needed to comply with
* a signature.
*
* @since 2.1
*/
public static JsonMappingException fromUnexpectedIOE(IOException src) {
return new JsonMappingException(null,
String.format("Unexpected IOException (of type %s): %s",
src.getClass().getName(), src.getMessage()));
}
/**
* Method that can be called to either create a new JsonMappingException
* (if underlying exception is not a JsonMappingException), or augment
* given exception with given path/reference information.
*
* This version of method is called when the reference is through a
* non-indexed object, such as a Map or POJO/bean.
*/
public static JsonMappingException wrapWithPath(Throwable src, Object refFrom,
String refFieldName) {
return wrapWithPath(src, new Reference(refFrom, refFieldName));
}
/**
* Method that can be called to either create a new JsonMappingException
* (if underlying exception is not a JsonMappingException), or augment
* given exception with given path/reference information.
*
* This version of method is called when the reference is through an
* index, which happens with arrays and Collections.
*/
public static JsonMappingException wrapWithPath(Throwable src, Object refFrom, int index) {
return wrapWithPath(src, new Reference(refFrom, index));
}
/**
* Method that can be called to either create a new JsonMappingException
* (if underlying exception is not a JsonMappingException), or augment
* given exception with given path/reference information.
*/
@SuppressWarnings("resource")
public static JsonMappingException wrapWithPath(Throwable src, Reference ref)
{
JsonMappingException jme;
if (src instanceof JsonMappingException) {
jme = (JsonMappingException) src;
} else {
String msg = src.getMessage();
// Let's use a more meaningful placeholder if all we have is null
if (msg == null || msg.length() == 0) {
msg = "(was "+src.getClass().getName()+")";
}
// 17-Aug-2015, tatu: Let's also pass the processor (parser/generator) along
Closeable proc = null;
if (src instanceof JsonProcessingException) {
Object proc0 = ((JsonProcessingException) src).getProcessor();
if (proc0 instanceof Closeable) {
proc = (Closeable) proc0;
}
}
jme = new Json
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
return;
}
}
gen.writeStartArray(len);
serializeContents(value, gen, provider);
gen.writeEndArray();
}
@Override
public void serializeContents(List<?> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException
{
if (_elementSerializer != null) {
serializeContentsUsing(value, jgen, provider, _elementSerializer);
return;
}
if (_valueTypeSerializer != null) {
serializeTypedContents(value, jgen, provider);
return;
}
final int len = value.size();
if (len == 0) {
return;
}
int i = 0;
try {
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
Object elem = value.get(i);
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicSerializers;
}
serializer.serialize(elem, jgen, provider);
}
}
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
}
public void serializeContentsUsing(List<?> value, JsonGenerator jgen, SerializerProvider provider,
JsonSerializer<Object> ser)
throws IOException
{
final int len = value.size();
if (len == 0) {
return;
}
final TypeSerializer typeSer = _valueTypeSerializer;
for (int i = 0; i < len; ++i) {
Object elem = value.get(i);
try {
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
wrapAndThrow(provider, e, value, i);
}
}
}
public void serializeTypedContents(List
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS><?> value, JsonGenerator jgen, SerializerProvider provider)
throws IOException
{
final int len = value.size();
if (len == 0) {
return;
}
int i = 0;
try {
final TypeSerializer typeSer = _valueTypeSerializer;
PropertySerializerMap serializers = _dynamicSerializers;
for (; i < len; ++i) {
Object elem = value.get(i);
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
// To fix [JACKSON-508]
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicSerializers;
}
serializer.serializeWithType(elem, jgen, provider, typeSer);
}
}
} catch (Exception e) {
// [JACKSON-55] Need to add reference information
wrapAndThrow(provider, e, value, i);
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>flag of {@link com.fasterxml.jackson.core.JsonParser.Feature}s to enable/disable
*/
protected final int _parserFeaturesToChange;
/**
* States of {@link com.fasterxml.jackson.core.FormatFeature}s to enable/disable.
*
* @since 2.7
*/
protected final int _formatReadFeatures;
/**
* Bitflag of {@link com.fasterxml.jackson.core.FormatFeature}s to enable/disable
*
* @since 2.7
*/
protected final int _formatReadFeaturesToChange;
/*
/**********************************************************
/* Life-cycle, constructors
/**********************************************************
*/
/**
* Constructor used by ObjectMapper to create default configuration object instance.
*/
public DeserializationConfig(BaseSettings base,
SubtypeResolver str, SimpleMixInResolver mixins,
RootNameLookup rootNames)
{
super(base, str, mixins, rootNames);
_deserFeatures = collectFeatureDefaults(DeserializationFeature.class);
_nodeFactory = JsonNodeFactory.instance;
_problemHandlers = null;
_parserFeatures = 0;
_parserFeaturesToChange = 0;
_formatReadFeatures = 0;
_formatReadFeaturesToChange = 0;
}
private DeserializationConfig(DeserializationConfig src,
int mapperFeatures, int deserFeatures,
int parserFeatures, int parserFeatureMask,
int formatFeatures, int formatFeatureMask)
{
super(src, mapperFeatures);
_deserFeatures = deserFeatures;
_nodeFactory = src._nodeFactory;
_problemHandlers = src._problemHandlers;
_parserFeatures = parserFeatures;
_parserFeaturesToChange = parserFeatureMask;
_formatReadFeatures = formatFeatures;
_formatReadFeaturesToChange = formatFeatureMask;
}
/**
* Copy constructor used to create a non-shared instance with given mix-in
* annotation definitions and subtype resolver.
*/
private DeserializationConfig(DeserializationConfig src, SubtypeResolver str)
{
super(src, str);
_deserFeatures = src._deserFeatures;
_nodeFactory = src._nodeFactory;
_problemHandlers = src._problemHandlers;
_parserFeatures = src._parserFeatures;
_parserFeaturesToChange = src._parserFeaturesToChange;
_formatReadFeatures = src._formatReadFeatures;
_formatReadFeaturesToChange = src._formatReadFeaturesToChange;
}
private DeserializationConfig(DeserializationConfig src, BaseSettings base)
{
super(src, base);
_deser
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>,
_parserFeatures, _parserFeaturesToChange,
_formatReadFeatures, _formatReadFeaturesToChange);
}
@Override
public DeserializationConfig with(MapperFeature feature, boolean state)
{
int newMapperFlags;
if (state) {
newMapperFlags = _mapperFeatures | feature.getMask();
} else {
newMapperFlags = _mapperFeatures & ~feature.getMask();
}
return (newMapperFlags == _mapperFeatures) ? this :
new DeserializationConfig(this, newMapperFlags, _deserFeatures,
_parserFeatures, _parserFeaturesToChange,
_formatReadFeatures, _formatReadFeaturesToChange);
}
@Override
public DeserializationConfig with(ClassIntrospector ci) {
return _withBase(_base.withClassIntrospector(ci));
}
@Override
public DeserializationConfig with(AnnotationIntrospector ai) {
return _withBase(_base.withAnnotationIntrospector(ai));
}
@Override
public DeserializationConfig with(VisibilityChecker<?> vc) {
return _withBase(_base.withVisibilityChecker(vc));
}
@Override
public DeserializationConfig withVisibility(PropertyAccessor forMethod, JsonAutoDetect.Visibility visibility) {
return _withBase( _base.withVisibility(forMethod, visibility));
}
@Override
public DeserializationConfig with(TypeResolverBuilder<?> trb) {
return _withBase(_base.withTypeResolverBuilder(trb));
}
@Override
public DeserializationConfig with(SubtypeResolver str) {
return (_subtypeResolver == str) ? this : new DeserializationConfig(this, str);
}
@Override
public DeserializationConfig with(PropertyNamingStrategy pns) {
return _withBase(_base.withPropertyNamingStrategy(pns));
}
@Override
public DeserializationConfig withRootName(PropertyName rootName) {
if (rootName == null) {
if (_rootName == null) {
return this;
}
} else if (rootName.equals(_rootName)) {
return this;
}
return new DeserializationConfig(this, rootName);
}
@Override
public DeserializationConfig with(TypeFactory tf) {
return _withBase( _base.withTypeFactory(tf));
}
@Override
public DeserializationConfig with(DateFormat df) {
return _withBase(_base.withDateFormat(df));
}
@Override
public DeserializationConfig with(HandlerInstantiator hi) {
return _withBase(_base.withHandler
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.annotation.Annotation;
import java.util.*;
import com.fasterxml.jackson.databind.util.Annotations;
/**
* Simple helper class used to keep track of collection of
* Jackson Annotations associated with annotatable things
* (methods, constructors, classes).
* Note that only Jackson-owned annotations are tracked (for now?).
*/
public final class AnnotationMap implements Annotations
{
protected HashMap<Class<?>,Annotation> _annotations;
public AnnotationMap() { }
private AnnotationMap(HashMap<Class<?>,Annotation> a) {
_annotations = a;
}
@SuppressWarnings("unchecked")
@Override
public <A extends Annotation> A get(Class<A> cls)
{
if (_annotations == null) {
return null;
}
return (A) _annotations.get(cls);
}
public boolean has(Class<?> cls)
{
if (_annotations == null) {
return false;
}
return _annotations.containsKey(cls);
}
/**
* Helper method that can be used for a "bulk" check to see if at least
* one of given annotation types is included within this map.
*
* @since 2.7
*/
public boolean hasOneOf(Class<? extends Annotation>[] annoClasses) {
if (_annotations != null) {
for (int i = 0, end = annoClasses.length; i < end; ++i) {
if (_annotations.containsKey(annoClasses[i])) {
return true;
}
}
}
return false;
}
/**
* @since 2.3
*/
public Iterable<Annotation> annotations() {
if (_annotations == null || _annotations.size() == 0) {
return Collections.emptyList();
}
return _annotations.values();
}
public static AnnotationMap merge(AnnotationMap primary, AnnotationMap secondary)
{
if (primary == null || primary._annotations == null || primary._annotations.isEmpty()) {
return secondary;
}
if (secondary == null || secondary._annotations == null || secondary._annotations.isEmpty()) {
return primary;
}
HashMap<Class<?>,Annotation> annotations = new HashMap<Class<?>,Annotation>();
// add secondary ones first
for (Annotation ann : secondary._annotations.values()) {
annotations.put(ann.annotationType(), ann);
}
// to be overridden by primary ones
for (Annotation ann : primary._annotations.values()) {
annotations.put(ann.annotationType
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>, type deserializer needs context as well
TypeDeserializer valueTypeDeser = _valueTypeDeserializer;
if (valueTypeDeser != null) {
valueTypeDeser = valueTypeDeser.forProperty(property);
}
return withResolved(delegateDeser, valueDeser, valueTypeDeser, unwrapSingle);
}
/*
/**********************************************************
/* ContainerDeserializerBase API
/**********************************************************
*/
@Override
public JavaType getContentType() {
return _collectionType.getContentType();
}
@Override
public JsonDeserializer<Object> getContentDeserializer() {
return _valueDeserializer;
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@SuppressWarnings("unchecked")
@Override
public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
if (_delegateDeserializer != null) {
return (Collection<Object>) _valueInstantiator.createUsingDelegate(ctxt,
_delegateDeserializer.deserialize(p, ctxt));
}
/* [JACKSON-620]: empty String may be ok; bit tricky to check, however, since
* there is also possibility of "auto-wrapping" of single-element arrays.
* Hence we only accept empty String here.
*/
if (p.hasToken(JsonToken.VALUE_STRING)) {
String str = p.getText();
if (str.length() == 0) {
return (Collection<Object>) _valueInstantiator.createFromString(ctxt, str);
}
}
return deserialize(p, ctxt, (Collection<Object>) _valueInstantiator.createUsingDefault(ctxt));
}
@Override
public Collection<Object> deserialize(JsonParser p, DeserializationContext ctxt,
Collection<Object> result)
throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!p.isExpectedStartArrayToken()) {
return handleNonArray(p, ctxt, result);
}
// [databind#631]: Assign current value, to be accessible by custom serializers
p.setCurrentValue(result);
JsonDeserializer<Object> valueDes = _valueDeserializer;
final TypeDeserializer typeDeser = _valueTypeDeserializer;
CollectionReferringAccumulator referringAccumulator =
(valueDes.getObjectIdReader() == null) ? null :
new CollectionReferringAccumulator(_collectionType.getContentType().getRawClass(), result);
JsonToken t;
while ((t = p.nextToken()) != JsonToken.END_ARRAY) {
try {
Object value;
if (t == JsonToken
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> will also
// do, with some constraints. But that will require bit post processing...
AnnotatedParameter nonAnnotatedParam = null;
SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
int explicitNameCount = 0;
int implicitWithCreatorCount = 0;
int injectCount = 0;
for (int i = 0; i < argCount; ++i) {
final AnnotatedParameter param = ctor.getParameter(i);
BeanPropertyDefinition propDef = (propDefs == null) ? null : propDefs[i];
Object injectId = intr.findInjectableValueId(param);
final PropertyName name = (propDef == null) ? null : propDef.getFullName();
if (propDef != null && propDef.isExplicitlyNamed()) {
++explicitNameCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
if (injectId != null) {
++injectCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
NameTransformer unwrapper = intr.findUnwrappingNameTransformer(param);
if (unwrapper != null) {
properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null);
++explicitNameCount;
continue;
}
// One more thing: implicit names are ok iff ctor has creator annotation
if (isCreator && (name != null && !name.isEmpty())) {
++implicitWithCreatorCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
if (nonAnnotatedParam == null) {
nonAnnotatedParam = param;
}
}
final int namedCount = explicitNameCount + implicitWithCreatorCount;
// Ok: if named or injectable, we have more work to do
if (isCreator || (explicitNameCount > 0) || (injectCount > 0)) {
// simple case; everything covered:
if ((namedCount + injectCount) == argCount) {
creators.addPropertyCreator(ctor, isCreator, properties);
continue;
}
if ((explicitNameCount == 0) && ((injectCount + 1) == argCount)) {
// Secondary: all but one injectable, one un-annotated (un-named)
creators.addDelegatingCreator(ctor, isCreator, properties);
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>BeanProperty[] properties = new SettableBeanProperty[argCount];
for (int i = 0; i < argCount; ++i) {
final AnnotatedParameter param = ctor.getParameter(i);
final PropertyName name = _findParamName(param, intr);
// must have name (implicit fine)
if (name == null || name.isEmpty()) {
continue main_loop;
}
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, param.getIndex(),
param, /*injectId*/ null);
}
if (found != null) { // only one allowed
found = null;
break;
}
found = ctor;
foundProps = properties;
}
// found one and only one visible? Ship it!
if (found != null) {
creators.addPropertyCreator(found, /*isCreator*/ false, foundProps);
BasicBeanDescription bbd = (BasicBeanDescription) beanDesc;
// Also: add properties, to keep error messages complete wrt known properties...
for (SettableBeanProperty prop : foundProps) {
PropertyName pn = prop.getFullName();
if (!bbd.hasProperty(pn)) {
BeanPropertyDefinition newDef = SimpleBeanPropertyDefinition.construct(
ctxt.getConfig(), prop.getMember(), pn);
bbd.addProperty(newDef);
}
}
}
}
protected boolean _checkIfCreatorPropertyBased(AnnotationIntrospector intr,
AnnotatedWithParams creator, BeanPropertyDefinition propDef)
{
JsonCreator.Mode mode = intr.findCreatorBinding(creator);
if (mode == JsonCreator.Mode.PROPERTIES) {
return true;
}
if (mode == JsonCreator.Mode.DELEGATING) {
return false;
}
// If explicit name, or inject id, property-based
if (((propDef != null) && propDef.isExplicitlyNamed())
|| (intr.findInjectableValueId(creator.getParameter(0)) != null)) {
return true;
}
if (propDef != null) {
// One more thing: if implicit name matches property with a getter
// or field, we'll consider it property-based as well
String implName = propDef.getName();
if (implName != null && !implName.isEmpty()) {
if (propDef.couldSerialize()) {
return true;
}
}
}
// in absence of everything else, default to delegating
return false;
}
protected boolean _handleSingleArgumentConstructor(DeserializationContext ctxt,
BeanDescription beanDesc, VisibilityChecker
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> argDef = (propDefs == null) ? null : propDefs[0];
boolean useProps = _checkIfCreatorPropertyBased(intr, factory, argDef);
if (!useProps) { // not property based but delegating
/*boolean added=*/ _handleSingleArgumentFactory(config, beanDesc, vchecker, intr, creators,
factory, isCreator);
// otherwise just ignored
continue;
}
// fall through if there's name
} else {
// more than 2 args, must have @JsonCreator
if (!isCreator) {
continue;
}
}
// 1 or more args; all params must have name annotations
AnnotatedParameter nonAnnotatedParam = null;
SettableBeanProperty[] properties = new SettableBeanProperty[argCount];
int implicitNameCount = 0;
int explicitNameCount = 0;
int injectCount = 0;
for (int i = 0; i < argCount; ++i) {
final AnnotatedParameter param = factory.getParameter(i);
BeanPropertyDefinition propDef = (propDefs == null) ? null : propDefs[i];
Object injectId = intr.findInjectableValueId(param);
final PropertyName name = (propDef == null) ? null : propDef.getFullName();
if (propDef != null && propDef.isExplicitlyNamed()) {
++explicitNameCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
if (injectId != null) {
++injectCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
NameTransformer unwrapper = intr.findUnwrappingNameTransformer(param);
if (unwrapper != null) {
properties[i] = constructCreatorProperty(ctxt, beanDesc, UNWRAPPED_CREATOR_PARAM_NAME, i, param, null);
++implicitNameCount;
continue;
}
// One more thing: implicit names are ok iff ctor has creator annotation
if (isCreator) {
if (name != null && !name.isEmpty()) {
++implicitNameCount;
properties[i] = constructCreatorProperty(ctxt, beanDesc, name, i, param, injectId);
continue;
}
}
/* 25-Sep-2014, tatu: Actually, we may end up "losing" naming due to higher-priority constructor
* (see TestCreators#testConstructorCreator() test).
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> (TypeDeserializer) type.getTypeHandler();
// or if not, based on type being referenced:
if (typeDeser == null) {
typeDeser = findTypeDeserializer(config, type);
}
// Note: contextualization of typeDeser _should_ occur in constructor of CreatorProperty
// so it is not called directly here
SettableBeanProperty prop = new CreatorProperty(name, type, property.getWrapperName(),
typeDeser, beanDesc.getClassAnnotations(), param, index, injectableValueId,
metadata);
if (deser != null) {
// As per [Issue#462] need to ensure we contextualize deserializer before passing it on
deser = ctxt.handlePrimaryContextualization(deser, prop, type);
prop = prop.withValueDeserializer(deser);
}
return prop;
}
protected PropertyName _findParamName(AnnotatedParameter param, AnnotationIntrospector intr)
{
if (param != null && intr != null) {
PropertyName name = intr.findNameForDeserialization(param);
if (name != null) {
return name;
}
// 14-Apr-2014, tatu: Need to also consider possible implicit name
// (for JDK8, or via paranamer)
String str = intr.findImplicitPropertyName(param);
if (str != null && !str.isEmpty()) {
return PropertyName.construct(str);
}
}
return null;
}
protected PropertyName _findImplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
{
String str = intr.findImplicitPropertyName(param);
if (str != null && !str.isEmpty()) {
return PropertyName.construct(str);
}
return null;
}
@Deprecated // in 2.6, remove from 2.7
protected PropertyName _findExplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
{
if (param != null && intr != null) {
return intr.findNameForDeserialization(param);
}
return null;
}
@Deprecated // in 2.6, remove from 2.7
protected boolean _hasExplicitParamName(AnnotatedParameter param, AnnotationIntrospector intr)
{
if (param != null && intr != null) {
PropertyName n = intr.findNameForDeserialization(param);
return (n != null) && n.hasSimpleName();
}
return false;
}
/*
/**********************************************************
/* JsonDeserializerFactory impl: array deserializers
/********************************************************
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Resolver(config, propertyEntity, containerType);
JavaType contentType = containerType.getContentType();
// Defaulting: if no annotations on member, check class
if (b == null) {
return findTypeDeserializer(config, contentType);
}
// but if annotations found, may need to resolve subtypes:
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByTypeId(
config, propertyEntity, contentType);
return b.buildTypeDeserializer(config, contentType, subtypes);
}
/**
* Helper method called to find one of default serializers for "well-known"
* platform types: JDK-provided types, and small number of public Jackson
* API types.
*
* @since 2.2
*/
public JsonDeserializer<?> findDefaultDeserializer(DeserializationContext ctxt,
JavaType type, BeanDescription beanDesc)
throws JsonMappingException
{
Class<?> rawType = type.getRawClass();
// Object ("untyped"), String equivalents:
if (rawType == CLASS_OBJECT) {
// 11-Feb-2015, tatu: As per [databind#700] need to be careful wrt non-default Map, List.
DeserializationConfig config = ctxt.getConfig();
JavaType lt, mt;
if (_factoryConfig.hasAbstractTypeResolvers()) {
lt = _findRemappedType(config, List.class);
mt = _findRemappedType(config, Map.class);
} else {
lt = mt = null;
}
return new UntypedObjectDeserializer(lt, mt);
}
if (rawType == CLASS_STRING || rawType == CLASS_CHAR_BUFFER) {
return StringDeserializer.instance;
}
if (rawType == CLASS_ITERABLE) {
// [Issue#199]: Can and should 'upgrade' to a Collection type:
TypeFactory tf = ctxt.getTypeFactory();
JavaType[] tps = tf.findTypeParameters(type, CLASS_ITERABLE);
JavaType elemType = (tps == null || tps.length != 1) ? TypeFactory.unknownType() : tps[0];
CollectionType ct = tf.constructCollectionType(Collection.class, elemType);
// Should we re-introspect beanDesc? For now let's not...
return createCollectionDeserializer(ctxt, ct, beanDesc);
}
if (rawType == CLASS_MAP_ENTRY) {
// 28-Apr-2015, tatu: TypeFactory does it all for us
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> public final void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException
{
if (_value == null) {
serializers.defaultSerializeNull(gen);
} else if (_value instanceof JsonSerializable) {
((JsonSerializable) _value).serialize(gen, serializers);
} else {
gen.writeObject(_value);
}
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
/**
* Method that can be used to access the POJO this node wraps.
*/
public Object getPojo() { return _value; }
/*
/**********************************************************
/* Overridden standard methods
/**********************************************************
*/
@Override
public boolean equals(Object o)
{
if (o == this) return true;
if (o == null) return false;
if (o instanceof POJONode) {
return _pojoEquals((POJONode) o);
}
return false;
}
/**
* @since 2.3
*/
protected boolean _pojoEquals(POJONode other)
{
if (_value == null) {
return other._value == null;
}
return _value.equals(other._value);
}
@Override
public int hashCode() { return _value.hashCode(); }
@Override
public String toString()
{
// [databind#743]: Let's try indicating content type, for debugging purposes
if (_value instanceof byte[]) {
return String.format("(binary value of %d bytes)", ((byte[]) _value).length);
}
if (_value instanceof RawValue) {
return String.format("(raw value '%s')", ((RawValue) _value).toString());
}
return String.valueOf(_value);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> Added modifier has the highest priority (that is, it
* gets called before any already registered modifier).
*/
public DeserializerFactoryConfig withDeserializerModifier(BeanDeserializerModifier modifier)
{
if (modifier == null) {
throw new IllegalArgumentException("Can not pass null modifier");
}
BeanDeserializerModifier[] all = ArrayBuilders.insertInListNoDup(_modifiers, modifier);
return new DeserializerFactoryConfig(_additionalDeserializers, _additionalKeyDeserializers, all,
_abstractTypeResolvers, _valueInstantiators);
}
/**
* Fluent/factory method used to construct a configuration object that
* has same configuration as this instance plus one additional
* abstract type resolver.
* Added resolver has the highest priority (that is, it
* gets called before any already registered resolver).
*/
public DeserializerFactoryConfig withAbstractTypeResolver(AbstractTypeResolver resolver)
{
if (resolver == null) {
throw new IllegalArgumentException("Can not pass null resolver");
}
AbstractTypeResolver[] all = ArrayBuilders.insertInListNoDup(_abstractTypeResolvers, resolver);
return new DeserializerFactoryConfig(_additionalDeserializers, _additionalKeyDeserializers, _modifiers,
all, _valueInstantiators);
}
/**
* Fluent/factory method used to construct a configuration object that
* has same configuration as this instance plus specified additional
* value instantiator provider object.
* Added instantiator provider has the highest priority (that is, it
* gets called before any already registered resolver).
*
* @param instantiators Object that can provide {@link com.fasterxml.jackson.databind.deser.ValueInstantiator}s for
* constructing POJO values during deserialization
*/
public DeserializerFactoryConfig withValueInstantiators(ValueInstantiators instantiators)
{
if (instantiators == null) {
throw new IllegalArgumentException("Can not pass null resolver");
}
ValueInstantiators[] all = ArrayBuilders.insertInListNoDup(_valueInstantiators, instantiators);
return new DeserializerFactoryConfig(_additionalDeserializers, _additionalKeyDeserializers, _modifiers,
_abstractTypeResolvers, all);
}
public boolean hasDeserializers() { return _additionalDeserializers.length > 0; }
public boolean hasKeyDeserializers() { return _additionalKeyDeserializers.length > 0; }
public boolean hasDeserializerModifiers() { return _modifiers.length > 0; }
public boolean hasAbstractTypeResolvers() { return _abstractTypeResolvers.length > 0; }
public boolean hasValueInstantiators() { return _valueInstantiators.length > 0; }
public
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.ser.std;
import java.io.IOException;
import java.lang.reflect.Type;
import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JacksonStdImpl;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatVisitorWrapper;
/**
* This is the special serializer for regular {@link java.lang.String}s.
*<p>
* Since this is one of "native" types, no type information is ever
* included on serialization (unlike for most scalar types as of 1.5)
*/
@JacksonStdImpl
public final class StringSerializer
// NOTE: generic parameter changed from String to Object in 2.6, to avoid
// use of bridge methods
extends NonTypedScalarSerializerBase<Object>
{
private static final long serialVersionUID = 1L;
public StringSerializer() { super(String.class, false); }
/**
* For Strings, both null and Empty String qualify for emptiness.
*/
@Override
@Deprecated
public boolean isEmpty(Object value) {
String str = (String) value;
return (str == null) || (str.length() == 0);
}
@Override
public boolean isEmpty(SerializerProvider prov, Object value) {
String str = (String) value;
return (str == null) || (str.length() == 0);
}
@Override
public void serialize(Object value, JsonGenerator gen, SerializerProvider provider) throws IOException {
gen.writeString((String) value);
}
@Override
public JsonNode getSchema(SerializerProvider provider, Type typeHint) {
return createSchemaNode("string", true);
}
@Override
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException {
visitStringFormat(visitor, typeHint);
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Type.getContentType();
}
@Override
public JsonDeserializer<Object> getContentDeserializer() {
return _elementDeserializer;
}
/*
/**********************************************************
/* JsonDeserializer API
/**********************************************************
*/
@Override
public Object[] deserialize(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// Ok: must point to START_ARRAY (or equivalent)
if (!p.isExpectedStartArrayToken()) {
return handleNonArray(p, ctxt);
}
final ObjectBuffer buffer = ctxt.leaseObjectBuffer();
Object[] chunk = buffer.resetAndStart();
int ix = 0;
JsonToken t;
final TypeDeserializer typeDeser = _elementTypeDeserializer;
try {
while ((t = p.nextToken()) != JsonToken.END_ARRAY) {
// Note: must handle null explicitly here; value deserializers won't
Object value;
if (t == JsonToken.VALUE_NULL) {
value = _elementDeserializer.getNullValue(ctxt);
} else if (typeDeser == null) {
value = _elementDeserializer.deserialize(p, ctxt);
} else {
value = _elementDeserializer.deserializeWithType(p, ctxt, typeDeser);
}
if (ix >= chunk.length) {
chunk = buffer.appendCompletedChunk(chunk);
ix = 0;
}
chunk[ix++] = value;
}
} catch (Exception e) {
throw JsonMappingException.wrapWithPath(e, chunk, buffer.bufferedSize() + ix);
}
Object[] result;
if (_untyped) {
result = buffer.completeAndClearBuffer(chunk, ix);
} else {
result = buffer.completeAndClearBuffer(chunk, ix, _elementClass);
}
ctxt.returnObjectBuffer(buffer);
return result;
}
@Override
public Object[] deserializeWithType(JsonParser p, DeserializationContext ctxt,
TypeDeserializer typeDeserializer)
throws IOException
{
/* Should there be separate handling for base64 stuff?
* for now this should be enough:
*/
return (Object[]) typeDeserializer.deserializeTypedFromArray(p, ctxt);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected Byte[] deserializeFromBase64(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// First same as what PrimitiveArrayDeserializers.ByteDeser does:
byte[] b = p.getBinaryValue(ctxt.getBase64Variant());
// But then need to convert to wrappers
Byte[] result =
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> new Byte[b.length];
for (int i = 0, len = b.length; i < len; ++i) {
result[i] = Byte.valueOf(b[i]);
}
return result;
}
protected Object[] handleNonArray(JsonParser p, DeserializationContext ctxt)
throws IOException
{
// Empty String can become null...
if (p.hasToken(JsonToken.VALUE_STRING)
&& ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
String str = p.getText();
if (str.length() == 0) {
return null;
}
}
// Can we do implicit coercion to a single-element array still?
boolean canWrap = (_unwrapSingle == Boolean.TRUE) ||
((_unwrapSingle == null) &&
ctxt.isEnabled(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY));
if (!canWrap) {
// One exception; byte arrays are generally serialized as base64, so that should be handled
if (p.getCurrentToken() == JsonToken.VALUE_STRING
// note: not `byte[]`, but `Byte[]` -- former is primitive array
&& _elementClass == Byte.class) {
return deserializeFromBase64(p, ctxt);
}
throw ctxt.mappingException(_arrayType.getRawClass());
}
JsonToken t = p.getCurrentToken();
Object value;
if (t == JsonToken.VALUE_NULL) {
value = _elementDeserializer.getNullValue(ctxt);
} else if (_elementTypeDeserializer == null) {
value = _elementDeserializer.deserialize(p, ctxt);
} else {
value = _elementDeserializer.deserializeWithType(p, ctxt, _elementTypeDeserializer);
}
// Ok: bit tricky, since we may want T[], not just Object[]
Object[] result;
if (_untyped) {
result = new Object[1];
} else {
result = (Object[]) Array.newInstance(_elementClass, 1);
}
result[0] = value;
return result;
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
/* Accessors
/**********************************************************
*/
@Override
public boolean isEmpty(SerializerProvider prov, Collection<?> value) {
return (value == null) || value.isEmpty();
}
@Override
public boolean hasSingleElement(Collection<?> value) {
Iterator<?> it = value.iterator();
if (!it.hasNext()) {
return false;
}
it.next();
return !it.hasNext();
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public final void serialize(Collection<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
final int len = value.size();
if (len == 1) {
if (((_unwrapSingle == null) &&
provider.isEnabled(SerializationFeature.WRITE_SINGLE_ELEM_ARRAYS_UNWRAPPED))
|| (_unwrapSingle == Boolean.TRUE)) {
serializeContents(value, jgen, provider);
return;
}
}
jgen.writeStartArray(len);
serializeContents(value, jgen, provider);
jgen.writeEndArray();
}
@Override
public void serializeContents(Collection<?> value, JsonGenerator jgen, SerializerProvider provider) throws IOException
{
if (_elementSerializer != null) {
serializeContentsUsing(value, jgen, provider, _elementSerializer);
return;
}
Iterator<?> it = value.iterator();
if (!it.hasNext()) {
return;
}
PropertySerializerMap serializers = _dynamicSerializers;
final TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
try {
do {
Object elem = it.next();
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
Class<?> cc = elem.getClass();
JsonSerializer<Object> serializer = serializers.serializerFor(cc);
if (serializer == null) {
if (_elementType.hasGenericTypes()) {
serializer = _findAndAddDynamic(serializers,
provider.constructSpecializedType(_elementType, cc), provider);
} else {
serializer = _findAndAddDynamic(serializers, cc, provider);
}
serializers = _dynamicSerializers;
}
if (typeSer == null) {
serializer.serialize(elem, jgen, provider);
} else {
serializer.serializeWithType(elem, jgen, provider, typeSer);
}
}
++i;
} while (it.hasNext());
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> }
public void serializeContentsUsing(Collection<?> value, JsonGenerator jgen, SerializerProvider provider,
JsonSerializer<Object> ser)
throws IOException, JsonGenerationException
{
Iterator<?> it = value.iterator();
if (it.hasNext()) {
TypeSerializer typeSer = _valueTypeSerializer;
int i = 0;
do {
Object elem = it.next();
try {
if (elem == null) {
provider.defaultSerializeNull(jgen);
} else {
if (typeSer == null) {
ser.serialize(elem, jgen, provider);
} else {
ser.serializeWithType(elem, jgen, provider, typeSer);
}
}
++i;
} catch (Exception e) {
wrapAndThrow(provider, e, value, i);
}
} while (it.hasNext());
}
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.introspect;
import java.lang.reflect.*;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.util.ClassUtil;
public final class AnnotatedConstructor
extends AnnotatedWithParams
{
private static final long serialVersionUID = 1L;
protected final Constructor<?> _constructor;
/**
* Field that is used to make JDK serialization work with this
* object.
*
* @since 2.1
*/
protected Serialization _serialization;
/*
/**********************************************************
/* Life-cycle
/**********************************************************
*/
public AnnotatedConstructor(TypeResolutionContext ctxt, Constructor<?> constructor,
AnnotationMap classAnn, AnnotationMap[] paramAnn)
{
super(ctxt, classAnn, paramAnn);
if (constructor == null) {
throw new IllegalArgumentException("Null constructor not allowed");
}
_constructor = constructor;
}
/**
* Method used for JDK serialization support
* @since 2.1
*/
protected AnnotatedConstructor(Serialization ser)
{
super(null, null, null);
_constructor = null;
_serialization = ser;
}
@Override
public AnnotatedConstructor withAnnotations(AnnotationMap ann) {
return new AnnotatedConstructor(_typeContext, _constructor, ann, _paramAnnotations);
}
/*
/**********************************************************
/* Annotated impl
/**********************************************************
*/
@Override
public Constructor<?> getAnnotated() { return _constructor; }
@Override
public int getModifiers() { return _constructor.getModifiers(); }
@Override
public String getName() { return _constructor.getName(); }
@Override
public JavaType getType() {
return _typeContext.resolveType(getRawType());
}
@Override
public Class<?> getRawType() {
return _constructor.getDeclaringClass();
}
/*
/**********************************************************
/* Extended API
/**********************************************************
*/
@Override
public int getParameterCount() {
return _constructor.getParameterTypes().length;
}
@Override
public Class<?> getRawParameterType(int index)
{
Class<?>[] types = _constructor.getParameterTypes();
return (index >= types.length) ? null : types[index];
}
@Override
public JavaType getParameterType(int index) {
Type[] types = _constructor.getGenericParameterTypes();
if (index >= types.length) {
return null;
}
return _typeContext.resolveType(types[index]);
}
@Override
@Deprecated // since 2.7
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
public Type getGenericParameterType(int index) {
Type[] types = _constructor.getGenericParameterTypes();
if (index >= types.length) {
return null;
}
return types[index];
}
@Override
public final Object call() throws Exception {
return _constructor.newInstance();
}
@Override
public final Object call(Object[] args) throws Exception {
return _constructor.newInstance(args);
}
@Override
public final Object call1(Object arg) throws Exception {
return _constructor.newInstance(arg);
}
/*
/**********************************************************
/* AnnotatedMember impl
/**********************************************************
*/
@Override
public Class<?> getDeclaringClass() { return _constructor.getDeclaringClass(); }
@Override
public Member getMember() { return _constructor; }
@Override
public void setValue(Object pojo, Object value)
throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call setValue() on constructor of "
+getDeclaringClass().getName());
}
@Override
public Object getValue(Object pojo)
throws UnsupportedOperationException
{
throw new UnsupportedOperationException("Cannot call getValue() on constructor of "
+getDeclaringClass().getName());
}
/*
/**********************************************************
/* Extended API, specific annotations
/**********************************************************
*/
@Override
public String toString() {
return "[constructor for "+getName()+", annotations: "+_annotations+"]";
}
@Override
public int hashCode() {
return _constructor.getName().hashCode();
}
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (o == null || o.getClass() != getClass()) return false;
return ((AnnotatedConstructor) o)._constructor == _constructor;
}
/*
/**********************************************************
/* JDK serialization handling
/**********************************************************
*/
Object writeReplace() {
return new AnnotatedConstructor(new Serialization(_constructor));
}
Object readResolve() {
Class<?> clazz = _serialization.clazz;
try {
Constructor<?> ctor = clazz.getDeclaredConstructor(_serialization.args);
// 06-Oct-2012, tatu: Has "lost" its security override, must force back
if (!ctor.isAccessible()) {
ClassUtil.checkAndFixAccess(ctor, false);
}
return new AnnotatedConstructor(null, ctor, null, null);
} catch (Exception e) {
throw new IllegalArgumentException("Could not find constructor with "
+_serialization.args.length+" args from Class '"+clazz.getName());
}
}
/**
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
*/
@SuppressWarnings("unchecked")
public <T> T readValue(String src)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
_reportUndetectableSource(src);
}
return (T) _bindAndClose(_considerFilter(_parserFactory.createParser(src), false));
}
/**
* Method that binds content read from given byte array,
* using configuration of this reader.
* Value return is either newly constructed, or root value that
* was specified with {@link #withValueToUpdate(Object)}.
*/
@SuppressWarnings("unchecked")
public <T> T readValue(byte[] src)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
return (T) _detectBindAndClose(src, 0, src.length);
}
return (T) _bindAndClose(_considerFilter(_parserFactory.createParser(src), false));
}
/**
* Method that binds content read from given byte array,
* using configuration of this reader.
* Value return is either newly constructed, or root value that
* was specified with {@link #withValueToUpdate(Object)}.
*/
@SuppressWarnings("unchecked")
public <T> T readValue(byte[] src, int offset, int length)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
return (T) _detectBindAndClose(src, offset, length);
}
return (T) _bindAndClose(_considerFilter(_parserFactory.createParser(src, offset, length),
false));
}
@SuppressWarnings("unchecked")
public <T> T readValue(File src)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
return (T) _detectBindAndClose(_dataFormatReaders.findFormat(_inputStream(src)), true);
}
return (T) _bindAndClose(_considerFilter(_parserFactory.createParser(src), false));
}
/**
* Method that binds content read from given input source,
* using configuration of this reader.
* Value return is either newly constructed, or root value that
* was specified with {@link #withValueToUpdate(Object)}.
*/
@SuppressWarnings("unchecked")
public <T> T readValue(URL src)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
return (T) _detectBindAndClose(_dataFormatReaders.findFormat(_inputStream(src)), true
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> false);
}
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src), true));
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*/
@SuppressWarnings("resource")
public <T> MappingIterator<T> readValues(Reader src)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
_reportUndetectableSource(src);
}
JsonParser p = _considerFilter(_parserFactory.createParser(src), true);
_initForMultiRead(p);
p.nextToken();
DeserializationContext ctxt = createDeserializationContext(p);
return _newIterator(p, ctxt, _findRootDeserializer(ctxt), true);
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*
* @param json String that contains JSON content to parse
*/
@SuppressWarnings("resource")
public <T> MappingIterator<T> readValues(String json)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
_reportUndetectableSource(json);
}
JsonParser p = _considerFilter(_parserFactory.createParser(json), true);
_initForMultiRead(p);
p.nextToken();
DeserializationContext ctxt = createDeserializationContext(p);
return _newIterator(p, ctxt, _findRootDeserializer(ctxt), true);
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*/
public <T> MappingIterator<T> readValues(byte[] src, int offset, int length)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
return _detectBindAndReadValues(_dataFormatReaders.findFormat(src, offset, length), false);
}
return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src), true));
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*/
public final <T> MappingIterator<T> readValues(byte[] src)
throws IOException, JsonProcessingException {
return readValues(src, 0, src.length);
}
/**
* Overloaded version of {@link #readValue(InputStream)}.
*/
public <T> MappingIterator<T> readValues(File src)
throws IOException, JsonProcessingException
{
if (_dataFormatReaders != null) {
return _detectBindAndReadValues(
_dataFormatReaders.findFormat(_inputStream(src)), false);
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> (to match wrapper object with root name '"
+expSimpleName+"'), but "+p.getCurrentToken());
}
return result;
}
/*
/**********************************************************
/* Internal methods, format auto-detection
/**********************************************************
*/
@SuppressWarnings("resource")
protected Object _detectBindAndClose(byte[] src, int offset, int length) throws IOException
{
DataFormatReaders.Match match = _dataFormatReaders.findFormat(src, offset, length);
if (!match.hasMatch()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p = match.createParserWithMatch();
return match.getReader()._bindAndClose(p);
}
@SuppressWarnings("resource")
protected Object _detectBindAndClose(DataFormatReaders.Match match, boolean forceClosing)
throws IOException
{
if (!match.hasMatch()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p = match.createParserWithMatch();
// One more thing: we Own the input stream now; and while it's
// not super clean way to do it, we must ensure closure so:
if (forceClosing) {
p.enable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
}
// important: use matching ObjectReader (may not be 'this')
return match.getReader()._bindAndClose(p);
}
@SuppressWarnings("resource")
protected <T> MappingIterator<T> _detectBindAndReadValues(DataFormatReaders.Match match, boolean forceClosing)
throws IOException, JsonProcessingException
{
if (!match.hasMatch()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p = match.createParserWithMatch();
// One more thing: we Own the input stream now; and while it's
// not super clean way to do it, we must ensure closure so:
if (forceClosing) {
p.enable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
}
// important: use matching ObjectReader (may not be 'this')
return match.getReader()._bindAndReadValues(p);
}
@SuppressWarnings("resource")
protected JsonNode _detectBindAndCloseAsTree(InputStream in) throws IOException
{
DataFormatReaders.Match match = _dataFormatReaders.findFormat(in);
if (!match.hasMatch()) {
_reportUnkownFormat(_dataFormatReaders, match);
}
JsonParser p =
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> provider.constructType(_accessorMethod.getGenericReturnType());
// false -> no need to cache
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
* serializer from value serializer; but, alas, there's no access
* to serializer factory at this point...
*/
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
ser = provider.findPrimaryPropertySerializer(t, property);
/* 09-Dec-2010, tatu: Turns out we must add special handling for
* cases where "native" (aka "natural") type is being serialized,
* using standard serializer
*/
boolean forceTypeInformation = isNaturalTypeWithStdHandling(t.getRawClass(), ser);
return withResolved(property, ser, forceTypeInformation);
}
} else {
// 05-Sep-2013, tatu: I _think_ this can be considered a primary property...
ser = provider.handlePrimaryContextualization(ser, property);
return withResolved(property, ser, _forceTypeInformation);
}
return this;
}
/*
/**********************************************************
/* Actual serialization
/**********************************************************
*/
@Override
public void serialize(Object bean, JsonGenerator jgen, SerializerProvider prov) throws IOException
{
try {
Object value = _accessorMethod.invoke(bean);
if (value == null) {
prov.defaultSerializeNull(jgen);
return;
}
JsonSerializer<Object> ser = _valueSerializer;
if (ser == null) {
Class<?> c = value.getClass();
/* 10-Mar-2010, tatu: Ideally we would actually separate out type
* serializer from value serializer; but, alas, there's no access
* to serializer factory at this point...
*/
// let's cache it, may be needed soon again
ser = prov.findTypedValueSerializer(c, true, _property);
}
ser.serialize(value, jgen, prov);
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
Throwable t = e;
// Need to unwrap this specific type, to see infinite recursion...
while (t instanceof InvocationTargetException && t.getCause() != null) {
t = t.getCause();
}
// Errors shouldn't be wrapped (and often can't, as well)
if (t instanceof Error) {
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> consider <code>name()</code>
* to give explicit value).
*
* @since 2.7
*/
public String[] findEnumValues(Class<?> enumType, Enum<?>[] enumValues, String[] names) {
for (int i = 0, len = enumValues.length; i < len; ++i) {
/* 12-Mar-2016, tatu: This is quite tricky, considering that we should NOT
* overwrite values with default `name`... so for now, let's only delegate
* if no value has been set. Still not optimal but has to do
*/
// TODO: In 2.8, stop delegation?
if (names[i] == null) {
names[i] = findEnumValue(enumValues[i]);
}
}
return names;
}
/*
/**********************************************************
/* Deserialization: general annotations
/**********************************************************
*/
/**
* Method for getting a deserializer definition on specified method
* or field.
* Type of definition is either instance (of type
* {@link JsonDeserializer}) or Class (of type
* <code>Class<JsonDeserializer></code>); if value of different
* type is returned, a runtime exception may be thrown by caller.
*/
public Object findDeserializer(Annotated am) {
return null;
}
/**
* Method for getting a deserializer definition for keys of
* associated <code>Map</code> property.
* Type of definition is either instance (of type
* {@link JsonDeserializer}) or Class (of type
* <code>Class<JsonDeserializer></code>); if value of different
* type is returned, a runtime exception may be thrown by caller.
*/
public Object findKeyDeserializer(Annotated am) {
return null;
}
/**
* Method for getting a deserializer definition for content (values) of
* associated <code>Collection</code>, <code>array</code> or
* <code>Map</code> property.
* Type of definition is either instance (of type
* {@link JsonDeserializer}) or Class (of type
* <code>Class<JsonDeserializer></code>); if value of different
* type is returned, a runtime exception may be thrown by caller.
*/
public Object findContentDeserializer(Annotated am) {
return null;
}
/**
* Method for finding {@link Converter} that annotated entity
* (property or class) has indicated to be used as part of
* deserialization.
* If not null, either has
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>-String arg constructor (if no @JsonCreator)
if (!hasStringCreator && !hasDefaultCtor) {
throw JsonMappingException.from(p,"Can not deserialize Throwable of type "+_beanType
+" without having a default contructor, a single-String-arg constructor; or explicit @JsonCreator");
}
Object throwable = null;
Object[] pending = null;
int pendingIx = 0;
for (; p.getCurrentToken() != JsonToken.END_OBJECT; p.nextToken()) {
String propName = p.getCurrentName();
SettableBeanProperty prop = _beanProperties.find(propName);
p.nextToken(); // to point to field value
if (prop != null) { // normal case
if (throwable != null) {
prop.deserializeAndSet(p, ctxt, throwable);
continue;
}
// nope; need to defer
if (pending == null) {
int len = _beanProperties.size();
pending = new Object[len + len];
}
pending[pendingIx++] = prop;
pending[pendingIx++] = prop.deserialize(p, ctxt);
continue;
}
// Maybe it's "message"?
if (PROP_NAME_MESSAGE.equals(propName)) {
if (hasStringCreator) {
throwable = _valueInstantiator.createFromString(ctxt, p.getText());
// any pending values?
if (pending != null) {
for (int i = 0, len = pendingIx; i < len; i += 2) {
prop = (SettableBeanProperty)pending[i];
prop.set(throwable, pending[i+1]);
}
pending = null;
}
continue;
}
}
/* As per [JACKSON-313], things marked as ignorable should not be
* passed to any setter
*/
if (_ignorableProps != null && _ignorableProps.contains(propName)) {
p.skipChildren();
continue;
}
if (_anySetter != null) {
_anySetter.deserializeAndSet(p, ctxt, throwable, propName);
continue;
}
// Unknown: let's call handler method
handleUnknownProperty(p, ctxt, throwable, propName);
}
// Sanity check: did we find "message"?
if (throwable == null) {
/* 15-Oct-2010, tatu: Can't assume missing message is an error, since it may be
* suppressed during serialization, as per [JACKSON-388].
*
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
* Should probably allow use of default constructor, too...
*/
//throw new JsonMappingException("No 'message' property found: could not deserialize "+_beanType);
if (hasStringCreator) {
throwable = _valueInstantiator.createFromString(ctxt, null);
} else {
throwable = _valueInstantiator.createUsingDefault(ctxt);
}
// any pending values?
if (pending != null) {
for (int i = 0, len = pendingIx; i < len; i += 2) {
SettableBeanProperty prop = (SettableBeanProperty)pending[i];
prop.set(throwable, pending[i+1]);
}
}
}
return throwable;
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> handling
/**********************************************************
*/
@Override
public void flush() throws IOException { /* NOP */ }
@Override
public void close() throws IOException {
_closed = true;
}
@Override
public boolean isClosed() { return _closed; }
/*
/**********************************************************
/* JsonGenerator implementation: write methods, structural
/**********************************************************
*/
@Override
public final void writeStartArray() throws IOException
{
_writeContext.writeValue();
_append(JsonToken.START_ARRAY);
_writeContext = _writeContext.createChildArrayContext();
}
@Override
public final void writeEndArray() throws IOException
{
_append(JsonToken.END_ARRAY);
// Let's allow unbalanced tho... i.e. not run out of root level, ever
JsonWriteContext c = _writeContext.getParent();
if (c != null) {
_writeContext = c;
}
}
@Override
public final void writeStartObject() throws IOException
{
_writeContext.writeValue();
_append(JsonToken.START_OBJECT);
_writeContext = _writeContext.createChildObjectContext();
}
@Override
public final void writeEndObject() throws IOException
{
_append(JsonToken.END_OBJECT);
// Let's allow unbalanced tho... i.e. not run out of root level, ever
JsonWriteContext c = _writeContext.getParent();
if (c != null) {
_writeContext = c;
}
}
@Override
public final void writeFieldName(String name) throws IOException
{
_writeContext.writeFieldName(name);
_append(JsonToken.FIELD_NAME, name);
}
@Override
public void writeFieldName(SerializableString name) throws IOException
{
_writeContext.writeFieldName(name.getValue());
_append(JsonToken.FIELD_NAME, name);
}
/*
/**********************************************************
/* JsonGenerator implementation: write methods, textual
/**********************************************************
*/
@Override
public void writeString(String text) throws IOException {
if (text == null) {
writeNull();
} else {
_appendValue(JsonToken.VALUE_STRING, text);
}
}
@Override
public void writeString(char[] text, int offset, int len) throws IOException {
writeString(new String(text, offset, len));
}
@Override
public void writeString(SerializableString text) throws IOException {
if (text == null) {
writeNull();
} else {
_append
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>Value(JsonToken.VALUE_STRING, text);
}
}
@Override
public void writeRawUTF8String(byte[] text, int offset, int length) throws IOException
{
// could add support for buffering if we really want it...
_reportUnsupportedOperation();
}
@Override
public void writeUTF8String(byte[] text, int offset, int length) throws IOException
{
// could add support for buffering if we really want it...
_reportUnsupportedOperation();
}
@Override
public void writeRaw(String text) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(String text, int offset, int len) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(SerializableString text) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(char[] text, int offset, int len) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRaw(char c) throws IOException {
_reportUnsupportedOperation();
}
@Override
public void writeRawValue(String text) throws IOException {
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, new RawValue(text));
}
@Override
public void writeRawValue(String text, int offset, int len) throws IOException {
if (offset > 0 || len != text.length()) {
text = text.substring(offset, offset+len);
}
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, new RawValue(text));
}
@Override
public void writeRawValue(char[] text, int offset, int len) throws IOException {
_appendValue(JsonToken.VALUE_EMBEDDED_OBJECT, new String(text, offset, len));
}
/*
/**********************************************************
/* JsonGenerator implementation: write methods, primitive types
/**********************************************************
*/
@Override
public void writeNumber(short i) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_INT, Short.valueOf(i));
}
@Override
public void writeNumber(int i) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_INT, Integer.valueOf(i));
}
@Override
public void writeNumber(long l) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER_INT, Long.valueOf(l));
}
@Override
public void writeNumber(double d) throws IOException {
_appendValue(JsonToken.VALUE_NUMBER
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>(ObjectCodec c) { _codec = c; }
@Override
public Version version() {
return com.fasterxml.jackson.databind.cfg.PackageVersion.VERSION;
}
/*
/**********************************************************
/* Extended API beyond JsonParser
/**********************************************************
*/
public JsonToken peekNextToken() throws IOException
{
// closed? nothing more to peek, either
if (_closed) return null;
Segment seg = _segment;
int ptr = _segmentPtr+1;
if (ptr >= Segment.TOKENS_PER_SEGMENT) {
ptr = 0;
seg = (seg == null) ? null : seg.next();
}
return (seg == null) ? null : seg.type(ptr);
}
/*
/**********************************************************
/* Closeable implementation
/**********************************************************
*/
@Override
public void close() throws IOException {
if (!_closed) {
_closed = true;
}
}
/*
/**********************************************************
/* Public API, traversal
/**********************************************************
*/
@Override
public JsonToken nextToken() throws IOException
{
// If we are closed, nothing more to do
if (_closed || (_segment == null)) return null;
// Ok, then: any more tokens?
if (++_segmentPtr >= Segment.TOKENS_PER_SEGMENT) {
_segmentPtr = 0;
_segment = _segment.next();
if (_segment == null) {
return null;
}
}
_currToken = _segment.type(_segmentPtr);
// Field name? Need to update context
if (_currToken == JsonToken.FIELD_NAME) {
Object ob = _currentObject();
String name = (ob instanceof String) ? ((String) ob) : ob.toString();
_parsingContext.setCurrentName(name);
} else if (_currToken == JsonToken.START_OBJECT) {
_parsingContext = _parsingContext.createChildObjectContext(-1, -1);
} else if (_currToken == JsonToken.START_ARRAY) {
_parsingContext = _parsingContext.createChildArrayContext(-1, -1);
} else if (_currToken == JsonToken.END_OBJECT
|| _currToken == JsonToken.END_ARRAY) {
// Closing JSON Object/Array? Close matching context
_parsingContext = _parsingContext.getParent();
// but allow unbalanced cases too (more close markers)
if (_parsingContext == null) {
_parsingContext = JsonReadContext.createRootContext(null);
}
}
return _currToken;
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS> ? null : ob.toString();
}
if (_currToken == null) {
return null;
}
switch (_currToken) {
case VALUE_NUMBER_INT:
case VALUE_NUMBER_FLOAT:
Object ob = _currentObject();
return (ob == null) ? null : ob.toString();
default:
return _currToken.asString();
}
}
@Override
public char[] getTextCharacters() {
String str = getText();
return (str == null) ? null : str.toCharArray();
}
@Override
public int getTextLength() {
String str = getText();
return (str == null) ? 0 : str.length();
}
@Override
public int getTextOffset() { return 0; }
@Override
public boolean hasTextCharacters() {
// We never have raw buffer available, so:
return false;
}
/*
/**********************************************************
/* Public API, access to token information, numeric
/**********************************************************
*/
@Override
public BigInteger getBigIntegerValue() throws IOException
{
Number n = getNumberValue();
if (n instanceof BigInteger) {
return (BigInteger) n;
}
if (getNumberType() == NumberType.BIG_DECIMAL) {
return ((BigDecimal) n).toBigInteger();
}
// int/long is simple, but let's also just truncate float/double:
return BigInteger.valueOf(n.longValue());
}
@Override
public BigDecimal getDecimalValue() throws IOException
{
Number n = getNumberValue();
if (n instanceof BigDecimal) {
return (BigDecimal) n;
}
switch (getNumberType()) {
case INT:
case LONG:
return BigDecimal.valueOf(n.longValue());
case BIG_INTEGER:
return new BigDecimal((BigInteger) n);
default:
}
// float or double
return BigDecimal.valueOf(n.doubleValue());
}
@Override
public double getDoubleValue() throws IOException {
return getNumberValue().doubleValue();
}
@Override
public float getFloatValue() throws IOException {
return getNumberValue().floatValue();
}
@Override
public int getIntValue() throws IOException
{
// optimize common case:
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
return ((Number) _currentObject()).intValue();
}
return getNumberValue().intValue();
}
@Override
public long getLongValue() throws IOException {
return getNumberValue().longValue();
}
@Override
public NumberType getNumberType() throws IOException
{
Number n = getNumberValue
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>();
if (n instanceof Integer) return NumberType.INT;
if (n instanceof Long) return NumberType.LONG;
if (n instanceof Double) return NumberType.DOUBLE;
if (n instanceof BigDecimal) return NumberType.BIG_DECIMAL;
if (n instanceof BigInteger) return NumberType.BIG_INTEGER;
if (n instanceof Float) return NumberType.FLOAT;
if (n instanceof Short) return NumberType.INT; // should be SHORT
return null;
}
@Override
public final Number getNumberValue() throws IOException {
_checkIsNumber();
Object value = _currentObject();
if (value instanceof Number) {
return (Number) value;
}
// Difficult to really support numbers-as-Strings; but let's try.
// NOTE: no access to DeserializationConfig, unfortunately, so can not
// try to determine Double/BigDecimal preference...
if (value instanceof String) {
String str = (String) value;
if (str.indexOf('.') >= 0) {
return Double.parseDouble(str);
}
return Long.parseLong(str);
}
if (value == null) {
return null;
}
throw new IllegalStateException("Internal error: entry should be a Number, but is of type "
+value.getClass().getName());
}
/*
/**********************************************************
/* Public API, access to token information, other
/**********************************************************
*/
@Override
public Object getEmbeddedObject()
{
if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT) {
return _currentObject();
}
return null;
}
@Override
@SuppressWarnings("resource")
public byte[] getBinaryValue(Base64Variant b64variant) throws IOException, JsonParseException
{
// First: maybe we some special types?
if (_currToken == JsonToken.VALUE_EMBEDDED_OBJECT) {
// Embedded byte array would work nicely...
Object ob = _currentObject();
if (ob instanceof byte[]) {
return (byte[]) ob;
}
// fall through to error case
}
if (_currToken != JsonToken.VALUE_STRING) {
throw _constructError("Current token ("+_currToken+") not VALUE_STRING (or VALUE_EMBEDDED_OBJECT with byte[]), can not access as binary");
}
final String str = getText();
if (str == null) {
return null;
}
ByteArrayBuilder builder = _byteBuilder;
if (builder == null) {
_byteBuilder = builder = new ByteArrayBuilder(10
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>0);
} else {
_byteBuilder.reset();
}
_decodeBase64(str, builder, b64variant);
return builder.toByteArray();
}
@Override
public int readBinaryValue(Base64Variant b64variant, OutputStream out) throws IOException
{
byte[] data = getBinaryValue(b64variant);
if (data != null) {
out.write(data, 0, data.length);
return data.length;
}
return 0;
}
/*
/**********************************************************
/* Public API, native ids
/**********************************************************
*/
@Override
public boolean canReadObjectId() {
return _hasNativeObjectIds;
}
@Override
public boolean canReadTypeId() {
return _hasNativeTypeIds;
}
@Override
public Object getTypeId() {
return _segment.findTypeId(_segmentPtr);
}
@Override
public Object getObjectId() {
return _segment.findObjectId(_segmentPtr);
}
/*
/**********************************************************
/* Internal methods
/**********************************************************
*/
protected final Object _currentObject() {
return _segment.get(_segmentPtr);
}
protected final void _checkIsNumber() throws JsonParseException
{
if (_currToken == null || !_currToken.isNumeric()) {
throw _constructError("Current token ("+_currToken+") not numeric, can not use numeric value accessors");
}
}
@Override
protected void _handleEOF() throws JsonParseException {
_throwInternal();
}
}
/**
* Individual segment of TokenBuffer that can store up to 16 tokens
* (limited by 4 bits per token type marker requirement).
* Current implementation uses fixed length array; could alternatively
* use 16 distinct fields and switch statement (slightly more efficient
* storage, slightly slower access)
*/
protected final static class Segment
{
public final static int TOKENS_PER_SEGMENT = 16;
/**
* Static array used for fast conversion between token markers and
* matching {@link JsonToken} instances
*/
private final static JsonToken[] TOKEN_TYPES_BY_INDEX;
static {
// ... here we know that there are <= 15 values in JsonToken enum
TOKEN_TYPES_BY_INDEX = new JsonToken[16];
JsonToken[] t = JsonToken.values();
// and reserve entry 0 for "not available"
System.arraycopy(t, 1, TOKEN_TYPES_BY_INDEX, 1, Math.min(15, t
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>.length - 1));
}
// // // Linking
protected Segment _next;
// // // State
/**
* Bit field used to store types of buffered tokens; 4 bits per token.
* Value 0 is reserved for "not in use"
*/
protected long _tokenTypes;
// Actual tokens
protected final Object[] _tokens = new Object[TOKENS_PER_SEGMENT];
/**
* Lazily constructed Map for storing native type and object ids, if any
*/
protected TreeMap<Integer,Object> _nativeIds;
public Segment() { }
// // // Accessors
public JsonToken type(int index)
{
long l = _tokenTypes;
if (index > 0) {
l >>= (index << 2);
}
int ix = ((int) l) & 0xF;
return TOKEN_TYPES_BY_INDEX[ix];
}
public int rawType(int index)
{
long l = _tokenTypes;
if (index > 0) {
l >>= (index << 2);
}
int ix = ((int) l) & 0xF;
return ix;
}
public Object get(int index) {
return _tokens[index];
}
public Segment next() { return _next; }
/**
* Accessor for checking whether this segment may have native
* type or object ids.
*/
public boolean hasIds() {
return _nativeIds != null;
}
// // // Mutators
public Segment append(int index, JsonToken tokenType)
{
if (index < TOKENS_PER_SEGMENT) {
set(index, tokenType);
return null;
}
_next = new Segment();
_next.set(0, tokenType);
return _next;
}
public Segment append(int index, JsonToken tokenType,
Object objectId, Object typeId)
{
if (index < TOKENS_PER_SEGMENT) {
set(index, tokenType, objectId, typeId);
return null;
}
_next = new Segment();
_next.set(0, tokenType, objectId, typeId);
return _next;
}
public Segment append(int index, JsonToken tokenType, Object value)
{
if (index < TOKENS_PER_SEGMENT) {
set(index, tokenType, value);
return null;
}
_next = new Segment();
_next.set(0, tokenType, value);
return _next;
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>
}
_tokenTypes |= typeCode;
assignNativeIds(index, objectId, typeId);
}
private void set(int index, int rawTokenType, Object value)
{
_tokens[index] = value;
long typeCode = (long) rawTokenType;
if (index > 0) {
typeCode <<= (index << 2);
}
_tokenTypes |= typeCode;
}
private void set(int index, int rawTokenType, Object value, Object objectId, Object typeId)
{
_tokens[index] = value;
long typeCode = (long) rawTokenType;
if (index > 0) {
typeCode <<= (index << 2);
}
_tokenTypes |= typeCode;
assignNativeIds(index, objectId, typeId);
}
private final void assignNativeIds(int index, Object objectId, Object typeId)
{
if (_nativeIds == null) {
_nativeIds = new TreeMap<Integer,Object>();
}
if (objectId != null) {
_nativeIds.put(_objectIdIndex(index), objectId);
}
if (typeId != null) {
_nativeIds.put(_typeIdIndex(index), typeId);
}
}
/**
* @since 2.3
*/
public Object findObjectId(int index) {
return (_nativeIds == null) ? null : _nativeIds.get(_objectIdIndex(index));
}
/**
* @since 2.3
*/
public Object findTypeId(int index) {
return (_nativeIds == null) ? null : _nativeIds.get(_typeIdIndex(index));
}
private final int _typeIdIndex(int i) { return i+i; }
private final int _objectIdIndex(int i) { return i+i+1; }
}
}
JacksonDatabind, 56
<FILEB>
<CHANGES>
int ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
ix = _firstHyphenOrUnderscore(value);
<CHANGEE>
<CHANGES>
}
protected int _firstHyphenOrUnderscore(String str)
{
for (int i = 0, end = str.length(); i < end; ++i) {
char c = str.charAt(i);
if (c == '_' || c == '-') {
return i;
}
}
return -1;
<CHANGEE>
<FILEE>
<FILEB>
case STD_URI:
return URI.create(value);
case STD_CLASS:
try {
return ctxt.findClass(value);
} catch (Exception e) {
throw ctxt.instantiationException(_valueClass, ClassUtil.getRootCause(e));
}
case STD_JAVA_TYPE:
return ctxt.getTypeFactory().constructFromCanonical(value);
case STD_CURRENCY:
// will throw IAE if unknown:
return Currency.getInstance(value);
case STD_PATTERN:
// will throw IAE (or its subclass) if malformed
return Pattern.compile(value);
case STD_LOCALE:
{
<CHANGES>
int ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // single argument
return new Locale(value);
}
String first = value.substring(0, ix);
value = value.substring(ix+1);
<CHANGES>
ix = value.indexOf('_');
<CHANGEE>
if (ix < 0) { // two pieces
return new Locale(first, value);
}
String second = value.substring(0, ix);
return new Locale(first, second, value.substring(ix+1));
}
case STD_CHARSET:
return Charset.forName(value);
case STD_TIME_ZONE:
return TimeZone.getTimeZone(value);
case STD_INET_ADDRESS:
return InetAddress.getByName(value);
}
// host or unbracketed IPv6, without port number
return new InetSocketAddress(value, 0);
}
}
throw new IllegalArgumentException();
}
@Override
protected Object _deserializeFromEmptyString() throws IOException {
// As per [databind#398], URI requires special handling
if (_kind == STD_URI) {
return URI.create("");
}
// As per [databind#1123], Locale too
if (_kind == STD_LOCALE) {
return Locale.ROOT;
}
return super._deserializeFromEmptyString();
<CHANGES>
<CHANGEE>
}
}
}
<FILEE>
<SCANS>package com.fasterxml.jackson.databind.util;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
* Iterator implementation used to efficiently expose contents of an
* Array as read-only iterator.
*/
public class ArrayIterator<T> implements Iterator<T>, Iterable<T>
{
private final T[] _a;
private int _index;
public ArrayIterator(T[] a) {
_a = a;
_index = 0;
}
@Override
public boolean hasNext() { return _index < _a.length; }
@Override
public T next() {
if (_index >= _a.length) {
throw new NoSuchElementException();
}
return _a[_index++];
}
@Override public void remove() { throw new UnsupportedOperationException(); }
@Override public Iterator<T> iterator() { return this; }
}